Jump to content

Recommended Posts

Posted

Just posted this over at theSwamp, thought I'd share it with you fine people also.

 

I was inspired to write a few functions that will generate entities using the minimum possible data requirements - hence all other values are taken as default.

 

This is handy for those who want to quickly generate entities without having to look up what codes are necessary, and which are surplus to requirement. Also, it helps beginners to use the entmake function in their codes, without too much effort.

 

These, of course, are the quickest way to generate entities in AutoCAD - quicker than VL, and much quicker than a command call. Also, they are not affected by OSnap (so no need to turn it off).

 

Example of usage, to create a line from (0,0,0) to (1,0,0):

 

(Line '(0 0 0) '(1 0 0))

Yes, its as easy as that.

 

The functions will also return the entity name of the newly created entity (if successful), and so, no need to be using 'entlast'...

 

If you have any queries as to how to use them, just ask.

 

(defun 3DFace (p1 p2 p3 p4)
 (entmakex (list (cons 0 "3DFACE")
                 (cons 10 p1)
                 (cons 11 p2)
                 (cons 12 p3)
                 (cons 13 p4))))


(defun Arc (cen rad sAng eAng)
 (entmakex (list (cons 0 "ARC")
                 (cons 10  cen)
                 (cons 40  rad)
                 (cons 50 sAng)
                 (cons 51 eAng))))


(defun AttDef (tag prmpt def pt hgt flag)
 (entmakex (list (cons 0 "ATTDEF")
                 (cons 10   pt)
                 (cons 40  hgt)
                 (cons 1   def)
                 (cons 3 prmpt)
                 (cons 2   tag)
                 (cons 70 flag))))


(defun Circle (cen rad)
 (entmakex (list (cons 0 "CIRCLE")
                 (cons 10 cen)
                 (cons 40 rad))))


(defun Ellipse (cen maj ratio)
 (entmakex (list (cons 0 "ELLIPSE")
                 (cons 100 "AcDbEntity")
                 (cons 100 "AcDbEllipse")
                 (cons 10 cen)
                 (cons 11 maj)
                 (cons 40 ratio)
                 (cons 41 0)
                 (cons 42 (* 2 pi)))))


(defun Insert (pt Nme)
 (entmakex (list (cons 0 "INSERT")
                 (cons 2 Nme)
                 (cons 10 pt))))


(defun Line (p1 p2)
 (entmakex (list (cons 0 "LINE")
                 (cons 10 p1)
                 (cons 11 p2))))


(defun LWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda (p) (cons 10 p))) lst))))


(defun M-Text (pt str)
 (entmakex (list (cons 0 "MTEXT")         
                 (cons 100 "AcDbEntity")
                 (cons 100 "AcDbMText")
                 (cons 10 pt)
                 (cons 1 str))))


(defun Point (pt)
 (entmakex (list (cons 0 "POINT")
                 (cons 10 pt))))


(defun Polyline (lst)
 (entmakex (list (cons 0 "POLYLINE")
                 (cons 10 '(0 0 0))))
 (mapcar
   (function (lambda (p)
               (entmake (list (cons 0 "VERTEX") (cons 10 p))))) lst)
 (entmakex (list (cons 0 "SEQEND"))))


(defun Solid (p1 p2 p3 p4)
 (entmakex (list (cons 0 "SOLID")
                 (cons 10 p1)
                 (cons 11 p2)
                 (cons 12 p3)
                 (cons 13 p4))))                


(defun Text (pt hgt str)
 (entmakex (list (cons 0 "TEXT")
                 (cons 10  pt)
                 (cons 40 hgt)
                 (cons 1  str))))
 

(defun Trce (p1 p2 p3 p4)
 (entmakex (list (cons 0 "TRACE")
                 (cons 10 p1)
                 (cons 11 p2)
                 (cons 12 p3)
                 (cons 13 p4))))

(defun xLine (pt vec)
 (entmakex (list (cons 0 "XLINE")
                 (cons 100 "AcDbEntity")
                 (cons 100 "AcDbXline")
                 (cons 10 pt)
                 (cons 11 vec))))


(defun Layer (Nme)
 (entmake (list (cons 0 "LAYER")
                (cons 100 "AcDbSymbolTableRecord")
                (cons 100 "AcDbLayerTableRecord")
                (cons 2 Nme)
                (cons 70 0))))


(defun Layer (Nme Col Ltyp LWgt Plt)
 (entmake (list (cons 0 "LAYER")
                (cons 100 "AcDbSymbolTableRecord")
                (cons 100 "AcDbLayerTableRecord")
                (cons 2  Nme)
                (cons 70 0)
                (cons 62 Col)
                (cons 6 Ltyp)
                (cons 290 Plt)
                (cons 370 LWgt))))

The list is a working progress of course, but this is what I have so far.

 

Also, if the argument names aren't too clear, a reference as to what they mean can be found here.

 

Lee

  • Like 4
  • Thanks 1
Posted
Just posted this over at theSwamp, thought I'd share it with you fine people also.

 

I was inspired to write a few functions that will generate entities using the minimum possible data requirements - hence all other values are taken as default.

 

This is handy for those who want to quickly generate entities without having to look up what codes are necessary, and which are surplus to requirement. Also, it helps beginners to use the entmake function in their codes, without too much effort.

 

These, of course, are the quickest way to generate entities in AutoCAD - quicker than VL, and much quicker than a command call. Also, they are not affected by OSnap (so no need to turn it off).

 

Example of usage, to create a line from (0,0,0) to (1,0,0):

 

(Line '(0 0 0) '(1 0 0))

 

Yes, its as easy as that.

 

The functions will also return the entity name of the newly created entity (if successful), and so, no need to be using 'entlast'...

 

If you have any queries as to how to use them, just ask.

 

(defun 3DFace (p1 p2 p3 p4)
 (entmakex (list (cons 0 "3DFACE")
                 (cons 10 p1)
                 (cons 11 p2)
                 (cons 12 p3)
                 (cons 13 p4))))


(defun Arc (cen rad sAng eAng)
 (entmakex (list (cons 0 "ARC")
                 (cons 10  cen)
                 (cons 40  rad)
                 (cons 50 sAng)
                 (cons 51 eAng))))


(defun AttDef (tag prmpt def pt hgt flag)
 (entmakex (list (cons 0 "ATTDEF")
                 (cons 10   pt)
                 (cons 40  hgt)
                 (cons 1   def)
                 (cons 3 prmpt)
                 (cons 2   tag)
                 (cons 70 flag))))


(defun Circle (cen rad)
 (entmakex (list (cons 0 "CIRCLE")
                 (cons 10 cen)
                 (cons 40 rad))))


(defun Ellipse (cen maj ratio)
 (entmakex (list (cons 0 "ELLIPSE")
                 (cons 100 "AcDbEntity")
                 (cons 100 "AcDbEllipse")
                 (cons 10 cen)
                 (cons 11 maj)
                 (cons 40 ratio)
                 (cons 41 0)
                 (cons 42 (* 2 pi)))))


(defun Insert (pt Nme)
 (entmakex (list (cons 0 "INSERT")
                 (cons 2 Nme)
                 (cons 10 pt))))


(defun Line (p1 p2)
 (entmakex (list (cons 0 "LINE")
                 (cons 10 p1)
                 (cons 11 p2))))


(defun LWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda (p) (cons 10 p))) lst))))


(defun M-Text (pt str)
 (entmakex (list (cons 0 "MTEXT")         
                 (cons 100 "AcDbEntity")
                 (cons 100 "AcDbMText")
                 (cons 10 pt)
                 (cons 1 str))))


(defun Point (pt)
 (entmakex (list (cons 0 "POINT")
                 (cons 10 pt))))


(defun Polyline (lst / x)
 (entmakex (list (cons 0 "POLYLINE")
                 (cons 10 '(0 0 0))))  
 (while (setq x (car lst))
   (entmakex (list (cons 0 "VERTEX")
                   (cons 10 x)))
   (setq lst (cdr lst)))
 (entmakex (list (cons 0 "SEQEND"))))


(defun Solid (p1 p2 p3 p4)
 (entmakex (list (cons 0 "SOLID")
                 (cons 10 p1)
                 (cons 11 p2)
                 (cons 12 p3)
                 (cons 13 p4))))                


(defun Text (pt hgt str)
 (entmakex (list (cons 0 "TEXT")
                 (cons 10  pt)
                 (cons 40 hgt)
                 (cons 1  str))))


(defun Trce (p1 p2 p3 p4)
 (entmakex (list (cons 0 "TRACE")
                 (cons 10 p1)
                 (cons 11 p2)
                 (cons 12 p3)
                 (cons 13 p4))))

(defun xLine (pt vec)
 (entmakex (list (cons 0 "XLINE")
                 (cons 100 "AcDbEntity")
                 (cons 100 "AcDbXline")
                 (cons 10 pt)
                 (cons 11 vec))))

 

The list is a working progress of course, but this is what I have so far.

 

Lee

 

 

Thanks Lee,

Thats a great help for many.

 

I am sure its more than a matter of preference, But what is the key difference between entmake and entmakex?

I believe this came up once before, But I really do not remember much about it.

Posted

Thanks Lee, your efforts are appreciated.

Posted

entmake:
If successful, entmake returns the entity's list of definition data.

entmakex:
If successful, entmakex returns the name of the entity created

 

Depending on what you intend to do with the entity once it is created.

  • Thanks 1
Posted
I am sure its more than a matter of preference, But what is the key difference between entmake and entmakex?

I believe this came up once before, But I really do not remember much about it.

 

As Tim said - entmakex returns the newly created entity ename - which is more useful than the entget data in most cases :)

 

Thanks Lee, your efforts are appreciated.

 

Thanks Larry :)

Posted
entmake:
If successful, entmake returns the entity's list of definition data.

entmakex:
If successful, entmakex returns the name of the entity created

 

Depending on what you intend to do with the entity once it is created.

 

 

Thanks Tim,

 

I can see how this might be useful.

Posted

It should be noted that the DXF groups for Linetype ( 6 ) Layer ( 8 ) Thickness ( 39 ) Linetypescale ( 48 ) Color ( 62 ) Tilemode ( 67 ) default to their current sysvar values.

 

OCS ( 210 ) Defaults WCS ( 0 0 1 )

 

So you could end up with a red hidden 12" high line -David

Posted
It should be noted that the DXF groups for Linetype ( 6 ) Layer ( 8 ) Thickness ( 39 ) Linetypescale ( 48 ) Color ( 62 ) Tilemode ( 67 ) default to their current sysvar values.

 

OCS ( 210 ) Defaults WCS ( 0 0 1 )

 

So you could end up with a red hidden 12" high line -David

 

This is true, I think I mentioned that fact (not as elaborately as you) in the first post:

 

I was inspired to write a few functions that will generate entities using the minimum possible data requirements - hence all other values are taken as default.

 

But, as VovKa suggested over at theSwamp - perhaps the functions could be modified slightly to something like:

 

(defun Line (p1 p2 [color=Blue][b]ext[/b][/color])
 (entmakex ([b][color=Blue]append[/color][/b] (list (cons 0 "LINE")
                         (cons 10 p1)
                         (cons 11 p2)) [b][color=Blue]ext[/color][/b])))

To give more flexibility, where 'ext' is extra data you may want to include, for example:

 

(Line '(0 0 0) '(1 0 0) [b][color=Blue]nil[/color][/b])  [b][color=Green]==>[/color][/b] [b][color=DarkRed]Line using defaults[/color][/b]

(Line '(0 0 0) '(1 0 0) [b][color=Blue]'((8 . "[color=Red]NewLayer[/color]") (6 . "[color=Red]HIDDEN[/color]"))[/color][/b])

[color=Green][b]==>[/b][/color][b] [color=DarkRed]Line on Layer[/color][/b] [b][color=Red]'NewLayer'[/color][/b] [b][color=DarkRed]with Linetype[/color][/b] [b][color=Red]'Hidden'[/color][/b]

Just a few ideas,

 

Lee

Posted

Lee,

 

True, but you would need to check linetype and textstyles table existences first. Entmake doesn't do much error trapping when thing are missing. Just returns nil. -David

Posted
Lee,

 

True, but you would need to check linetype and textstyles table existences first. Entmake doesn't do much error trapping when thing are missing. Just returns nil. -David

 

Of course, but these are left to the user. :)

Posted

Hi Lee,

 

I finally got to test the function you provided me with to reduce the number of headers used for making poylines with entmake. Since this is an entmake thread, I thought I would bring this up.

 

Below is the function snippet you gave me to work with. I finally figured out how to feed this with a list and it works great. The only problem I am having now is how to take into consideration bulge factor. Since most of the entities I use have a zero bulge factor this is OK, But when I am creating arcs in the polyline, I need to place the bulge factor in its correct location within the list.

 

How could I accomodate bulge factor within this code?

 

(defun mklw (l / e)
   (entmakex (append (list (cons 0   "LWPOLYLINE")
                           (cons 100 "AcDbEntity")
                           (cons 100 "AcDbPolyline")
                           (cons 90 (length l))
                           (cons 70 1))
                     (mapcar (function (lambda (a) (cons 10 a))) l))))

 

Below is a LWPOLYLINE using different bulge factors within the list.

 

(entmake
 (list
   (cons 0 "LWPOLYLINE")
   (cons 100 "AcDbEntity")
   (cons 67 0)
   (cons 410 "Model")
   (cons 8 LNAM$)
   (cons 100 "AcDbPolyline")
   (cons 90 4)
   (cons 70 1)
   (cons 43 0.0)
   (cons 38 0.0)
   (cons 39 0.0)
   (cons 10 PT01#)
   (cons 40 0.0)
   (cons 41 0.0)
   (cons 42 BF1#)      ;Calculated Bulge Factor 1
   (cons 10 PT02#)
   (cons 40 0.0)
   (cons 41 0.0)
   (cons 42 0.0)       ;Zero Bulge Factor
   (cons 10 PT03#)
   (cons 40 0.0)
   (cons 41 0.0)
   (cons 42 BF2#)      ;Calculated Bulge Factor 2
   (cons 10 PT04#)
   (cons 40 0.0)
   (cons 41 0.0)
   (cons 42 0.0)       ;Zero Bulge Factor
   (cons 210 EXDR#)))

Posted

Hi Buzzard,

 

There are a number of ways you could do it, depending on how you want to format your input arguments.

 

Here is one way:

 

(defun mklw  (l b cls / e)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length l))
                         (cons 70 cls))
                   (apply (function append)
                          (mapcar
                            (function
                              (lambda (a b)
                                (list (cons 10 a) (cons 42 b)))) l b)))))

 

I have also added an argument for whether the resultant poly is closed.

 

To use this function supply it with a list of polyline points, and their corresponding bulges, hence:

 

(mklw '(([color=SeaGreen][b]-190.351 -35.0871 0.0[/b][/color]) ([b][color=SeaGreen]-180.863 -78.9946 0.0[/color][/b])  [color=DarkRed][b]; Points[/b]
[/color]        ([b][color=SeaGreen]-135.166 -55.7836 0.0[/color][/b]) ([b][color=SeaGreen]-160.919 -42.8241 0.0[/color][/b]))

     '([color=SeaGreen][b]0.2 0.0 0.5 0.7[/b][/color])   [color=DarkRed][b]; Bulges[/b][/color]

     [color=Green][b]1[/b][/color]) [b][color=DarkRed]; Closed 

 

[/color][/b]If you are stuck at all, just ask.

 

Lee

Posted

Can you entmake a complex linetype? Everything I can find on the topic says NO.

Posted
Unfortunately, I'm inclined to agree...

 

I'm sure you can do it in ObjectARX, but how about in VB.NET?

Posted
I'm sure you can do it in ObjectARX, but how about in VB.NET?

 

Perhaps - you would have to ask those more knowledgeable than I :oops:

Posted
Hi Buzzard,

 

There are a number of ways you could do it, depending on how you want to format your input arguments.

 

Here is one way:

 

(defun mklw  (l b cls / e)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length l))
                         (cons 70 cls))
                   (apply (function append)
                          (mapcar
                            (function
                              (lambda (a b)
                                (list (cons 10 a) (cons 42 b)))) l b)))))

 

I have also added an argument for whether the resultant poly is closed.

 

To use this function supply it with a list of polyline points, and their corresponding bulges, hence:

 

(mklw '(([color=seagreen][b]-190.351 -35.0871 0.0[/b][/color]) ([b][color=seagreen]-180.863 -78.9946 0.0[/color][/b])  [color=darkred][b]; Points[/b][/color]
       ([b][color=seagreen]-135.166 -55.7836 0.0[/color][/b]) ([b][color=seagreen]-160.919 -42.8241 0.0[/color][/b]))

     '([color=seagreen][b]0.2 0.0 0.5 0.7[/b][/color])   [color=darkred][b]; Bulges[/b][/color]

     [color=green][b]1[/b][/color]) [b][color=darkred]; Closed [/color][/b]

 

If you are stuck at all, just ask.

 

Lee

 

 

Hot Dog!

 

Lee,

 

Just took it for a spin and it does the job. Now one function will fit for all the entities.

 

Thanks for that

The Buzzard

Posted
Hot Dog!

 

Lee,

 

Just took it for a spin and it does the job. Now one function will fit for all the entities.

 

Thanks for that

The Buzzard

 

You're welcome Buzzard, if you need me to explain the function at all, just shout and I'd be happy to :)

Posted
You're welcome Buzzard, if you need me to explain the function at all, just shout and I'd be happy to :)

 

 

I appreciate that Lee,

But I kind of got the idea now. I did not know that the second part of the function would also need to be appended. My lists are written slightly different as I am using variables instead, But it works all the same. When I made the attempt to adjust the function myself I did not have the second append as well as the arguments in there respected places.

 

I hope I get there someday.

Thanks again

Posted

You're welcome Buzzard :)

 

I did not know that the second part of the function would also need to be appended.

 

Just to clarify for those unsure:

 

mapcar will always return a list, containing the returns of the predicate function for each argument supplied to it.

 

Hence in our case, the mapcar statement would return something like:

 

(((10 . pt) (42 . blg))
((10 . pt) (42 . blg))
((10 . pt) (42 . blg)) ...)

 

After apply'ing append to this list we get:

 

((10 . pt) (42 . blg)
(10 . pt) (42 . blg)
(10 . pt) (42 . blg) ...)

 

Using apply in this way is the equivalent to writing:

 

(append ((10 . pt) (42 . blg))
       ((10 . pt) (42 . blg))
       ((10 . pt) (42 . blg)) ...)

 

Now, we have a list which we can append to the main DXF data.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...