Author Topic: When to use entmake?  (Read 9424 times)

0 Members and 1 Guest are viewing this topic.

StykFacE

  • Guest
When to use entmake?
« on: March 01, 2013, 11:58:29 AM »
I was digging around in the AutoCAD Developer's section and saw the example they provided with (entmake):
Code: [Select]
(entmake '((0 . "CIRCLE") (62 . 1) (10 4.0 4.0 0.0) (40 . 1.0)))
Does (entmake) only create static objects, or can I use something like (getpoint) to get user input on where to place the object? Also, is using DXF codes a thing of the past or is there more efficient ways on setting each property?

Thanks in advance.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: When to use entmake?
« Reply #1 on: March 01, 2013, 12:22:46 PM »
(entmake ...) is useful when you don't want to make (command ...) calls, or want to create large numbers of objects.  The arguments are a list of lists, which can be constructed programmatically while iterating over another list e.g. keep the object type, radius, layer, etc. the same while iterating over a list of coordinates; each cycle through builds a new list (or swaps out the coordinate list item) with the appropriate values, and fires it off with the (entmake ...).

DXF coding is still required for (entmake ...).  Personally, I find it useful as an indicator of expected values, and *usually* useful for pulling out specific items with (assoc ...).  The other way would be with Visual LISP, calling (vla-AddCircle ...) with appropriate arguments.  And thats a whole other ball of wax-like substance.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

StykFacE

  • Guest
Re: When to use entmake?
« Reply #2 on: March 01, 2013, 02:31:15 PM »
Thanks dgorsman. By chance, do you have any quick and easy examples? Anything will do, just so I can play with it a bit. <---- (out of context opportunity)

togores

  • Guest
Re: When to use entmake?
« Reply #3 on: March 01, 2013, 05:08:36 PM »
By chance, do you have any quick and easy examples? Anything will do, just so I can play with it a bit.
Hi StykFacE, take a look at my website posts in http://en.togores.net/home-vlisp. There you'll find examples for Xlines, blocks and layers...
Entmake is very powerful. For example, entmaking an entity with a given layer name will not only create an entity, but will also create the layer and place the entity in that layer. See the XLINE example.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: When to use entmake?
« Reply #4 on: March 01, 2013, 05:49:15 PM »
Hi Tannar,

The option of whether to use entmake[x] / command calls / ActiveX mostly depends on the application; entmake[x] is the certainly the fastest method for entity generation in AutoLISP, furthermore, many properties (e.g. Layer, Linetype, Lineweight, Colour etc.) may be set simultaneously through their relevant DXF groups in the data supplied to entmake[x], (whereas you would need to modify every property separately if using Visual LISP (vla-put-layer, vla-put-linetype, vla-put-color etc.). I also find it easier to account for changes in UCS when using entmake[x].

Since you were looking for simple examples, here are some simple programs for you to look over:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:myline ( / pt1 pt2 )
  2.     (if (setq pt1 (getpoint "\nSpecify First Point: "))
  3.         (while (setq pt2 (getpoint "\nSpecify Next Point: " pt1))
  4.             (entmake
  5.                 (list
  6.                    '(0 . "LINE")
  7.                     (cons 10 pt1)
  8.                     (cons 11 pt2)
  9.                 )
  10.             )
  11.             (setq pt1 pt2)
  12.         )
  13.     )
  14.     (princ)
  15. )
  16.  
  17. (defun c:mycircle ( / cen rad )
  18.     (if
  19.         (and
  20.             (setq cen (getpoint "\nSpecify Center: "))
  21.             (setq rad (getdist  "\nSpecify Radius: " cen))
  22.         )
  23.         (entmake
  24.             (list
  25.                '(0 . "CIRCLE")
  26.                 (cons 10 cen)
  27.                 (cons 40 rad)
  28.             )
  29.         )
  30.     )
  31.     (princ)
  32. )
  33.  
  34. (defun c:mypoint ( / pt1 )
  35.     (while (setq pt1 (getpoint "\nSpecify Point: "))
  36.         (entmake
  37.             (list
  38.                '(0 . "POINT")
  39.                 (cons 10 pt1)
  40.             )
  41.         )
  42.     )
  43.     (princ)
  44. )
  45.  
  46. (defun c:mypline ( / pt1 pt2 lst )
  47.     (if (setq pt1 (getpoint "\nSpecify First Point: "))
  48.         (progn
  49.             (setq lst (list (cons 10 pt1)))
  50.             (while (setq pt2 (getpoint "\nSpecify Next Point: " pt1))
  51.                 (setq lst (cons (cons 10 pt2) lst)
  52.                       pt1 pt2
  53.                 )
  54.             )
  55.             (entmake
  56.                 (append
  57.                     (list
  58.                        '(000 . "LWPOLYLINE")
  59.                        '(100 . "AcDbEntity")
  60.                        '(100 . "AcDbPolyline")
  61.                         (cons 90 (length lst))
  62.                        '(070 . 0)
  63.                     )
  64.                     (reverse lst)
  65.                 )
  66.             )
  67.         )
  68.     )
  69.     (princ)
  70. )
  71.  

Please note that, to keep things simple, the above programs use the minimum DXF groups to generate the entity (i.e. the entities will be created on the current layer, with colour set to CECOLOR, linetype set to CELTYPE etc.), and the above programs also do not account for changes in the UCS as I didn't want to overwhelm you with information at this stage.

If you have any questions about anything in this post, just ask and I'll be happy to explain.
« Last Edit: March 01, 2013, 05:53:14 PM by Lee Mac »

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: When to use entmake?
« Reply #5 on: March 01, 2013, 05:56:43 PM »
You might also find this post useful to demonstrate the differences between the various methods:

http://www.theswamp.org/index.php?topic=38964.msg441260#msg441260

DEVITG

  • Bull Frog
  • Posts: 479
Re: When to use entmake?
« Reply #6 on: March 01, 2013, 07:51:04 PM »
Thanks dgorsman. By chance, do you have any quick and easy examples? Anything will do, just so I can play with it a bit. <---- (out of context opportunity)

I have it simple  lisp to get the dxf code for an entity

Code: [Select]
(entget (car (entsel)))
It give the list for any enty , some code can not be stated , like  5 , handle , it is a read only , it can not be assigned, some are redundant

Location @ Córdoba Argentina Using ACAD 2019  at Window 10

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: When to use entmake?
« Reply #7 on: March 01, 2013, 09:33:29 PM »
Here is one to try:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:myentget+ (/ ent elst)
  2.   (if (and (setq ent (car (entsel "\nSelect entity to list.")))
  3.            (setq elst (entget ent '("*"))))
  4.     (progn
  5.       (textscr)
  6.       (princ "\n>>>------>  ")
  7.       (princ (vlax-ename->vla-object ent))
  8.       (mapcar 'print elst)
  9.       (mapcar
  10.         '(lambda(x / slst)
  11.       (if (and (assoc x elst)
  12.                (setq slst (entget (cdr (assoc x elst)))))
  13.         (progn
  14.           (prompt (strcat "\n\n*******  Dump DXF "(itoa x)" listing  *********"))
  15.           (foreach n slst (print n))
  16.         )
  17.       )
  18.            )
  19.         '(330 340)) ; '(320 330 340 350 360))
  20.     )
  21.   )
  22.   (princ)
  23. )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: When to use entmake?
« Reply #8 on: March 01, 2013, 09:37:07 PM »
This may be of interest too.
----------  Entmake   ----------------------
http://www.theswamp.org/index.php?topic=31145.0  ENTMAKE function by CAB
http://www.theswamp.org/index.php?topic=4814.msg112107#msg112107 
http://www.theswamp.org/index.php?topic=17445.0  Min codes
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

xiaxiang

  • Guest
Re: When to use entmake?
« Reply #9 on: March 02, 2013, 12:21:02 AM »
hi,Lee
It should be more wonderful if you can teach us how to use entmake correctly in the UCS,including insertpoint,rotation,etc
Regards, Xia

David Bethel

  • Swamp Rat
  • Posts: 656
Re: When to use entmake?
« Reply #10 on: March 02, 2013, 08:06:06 AM »
I prefer ( entmake ) for most parametric routines.  It gives you a lot more control.

Some gotchas are the defaults if a group code is missing.

Code: [Select]
                DXFIN        Entmake      Command
   6 Linetype  BYLAYER      CELTYPE      CELTYPE
  39 Thickness  0.0        THICKNESS     THICKNESS
  48 LTScale    1.0        CELTSCALE     CELTSCALE
  62 Color     BYLAYER      CECOLOR       CECOLOR
 210 UCS        WCS           WCS        Current UCS
 

Most of the documentation was made for DXFIN formats

One rule for entmake is that DXF group 0 must the fist listed.

They both have there pluses and drawbacks.  For example (command "_.INSERT" ...) must take into consideration whether the BLOCK has attributes.  Both need to address this, but in totally different methods.

As to the UCS  (cons 210 (trans '(0 0 1) 1 0) would ensure that entity is made in the current UCS.  The problem here is that many entities need WCS values only ( POINTs, LINEs, 3DFACEs, and POLYLINE meshes. And things like 3DFACEs do not have group 210


-David
R12 Dos - A2K

StykFacE

  • Guest
Re: When to use entmake?
« Reply #11 on: March 02, 2013, 09:20:54 AM »
If you have any questions about anything in this post, just ask and I'll be happy to explain.
Wow, such great responses!! Thanks to all. Lee, I will take you up on your offer. First, what's crazy to me, is for some reason I can actually follow the code. I guess me trolling through these forums and monkeying with enough code through the years is beginning to pay off a little. Weird...

Anyways, on to my questions.

Code: [Select]
(cons 10 pt1)(cons) is used to to take the user input from pt1, combine it with 10 to turn it into a dotted pair to generate the necessary syntax for the DXF code, correct? Why no apostrophe when using (cons)?

Code: [Select]
(progn)Reading the documentation I can't follow exactly what this function does. I read it, but just doesn't click for me? Hoping to get more insight from you if you wouldn't mind. ;)

Code: [Select]
(append
  (list
    '(000 . "LWPOLYLINE")
    '(100 . "AcDbEntity")
    '(100 . "AcDbPolyline")
     (cons 90 (length lst))
    '(070 . 0)
  )
  (reverse lst)
)
The (append) function is new to me, but after reading up on the documentation I think I follow. In your other lists from the first three main routines, you used multiple arguments but did not append them. Any particular reason you did on the c:mypline routine? Also, is the (list) function the only argument that (append) handles?

CAB, question for you my friend.
Code: [Select]
(mapcar
  '(lambda (x / slst)

Of all the code through the years I've monkeyed around with, I see the (mapcar) and (lambda) functions used a lot. After reading the documentation I'm assuming that the (lambda) function is just defining a function "on the fly" so to speak? I noticed that the x and slst symbols aren't localized at the beginning of the routine. Is this why the (lambda) function is used? To focus on the spot it's intended to be used, like the documentation states?

One rule for entmake is that DXF group 0 must the fist listed.
David, thank you for the gotcha's and tips. One quick question, is there any area of the documentation that defines the "rules" for properly formatting the DXF codes? I read from a post on another site the other day that DXF codes are to be listed in proper order. Sure enough, I tested Lee Mac's code above last night, mixed the DXF Group Code order in the list and things went wonky on me. The reason I ask is because I see there are common group codes and entity group codes, and I'm not sure on which codes go where when they're combined.

Very big thanks to all! :kewl:
« Last Edit: March 02, 2013, 09:28:12 AM by StykFacE »

StykFacE

  • Guest
Re: When to use entmake?
« Reply #12 on: March 02, 2013, 09:29:36 AM »
By chance, do you have any quick and easy examples? Anything will do, just so I can play with it a bit.
Hi StykFacE, take a look at my website posts in http://en.togores.net/home-vlisp. There you'll find examples for Xlines, blocks and layers...
Entmake is very powerful. For example, entmaking an entity with a given layer name will not only create an entity, but will also create the layer and place the entity in that layer. See the XLINE example.
togores, thanks for your reply also. I have bookmarked your website and plan on reading through it. The XLINE example was very informative.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: When to use entmake?
« Reply #13 on: March 02, 2013, 09:43:11 AM »
Tanner,

I haven't really found any what I would call documentation

There are only certain entity types where the order of the code is imperative.

LWPLOLYLINES
  Group 90 must be stated before group 10s
  Groups 10 41 42 declare the order of the points, so it imperative they are listed in the proper order.


Others would include SPLINEs MLINEs ( if you dare )

In general the group 0 1st is always the case

Here is simple box using parametric values


Code - Text: [Select]
  1. (setq x 20 y 30 z 40)
  2. (entmake (list (cons 0 "POLYLINE")(cons 66 1)(cons 10 (list 0 0 0))(cons 70 16)(cons 71 6)(cons 72 3)))
  3. (entmake (list (cons 0 "VERTEX")(cons 10 (list x 0 z))(cons 70 64)))
  4. (entmake (list (cons 0 "VERTEX")(cons 10 (list x 0 0))(cons 70 64)))
  5. (entmake (list (cons 0 "VERTEX")(cons 10 (list x 0 0))(cons 70 64)))
  6. (entmake (list (cons 0 "VERTEX")(cons 10 (list 0 0 z))(cons 70 64)))
  7. (entmake (list (cons 0 "VERTEX")(cons 10 (list 0 0 0))(cons 70 64)))
  8. (entmake (list (cons 0 "VERTEX")(cons 10 (list 0 0 0))(cons 70 64)))
  9. (entmake (list (cons 0 "VERTEX")(cons 10 (list 0 y z))(cons 70 64)))
  10. (entmake (list (cons 0 "VERTEX")(cons 10 (list 0 y 0))(cons 70 64)))
  11. (entmake (list (cons 0 "VERTEX")(cons 10 (list 0 0 0))(cons 70 64)))
  12. (entmake (list (cons 0 "VERTEX")(cons 10 (list x y z))(cons 70 64)))
  13. (entmake (list (cons 0 "VERTEX")(cons 10 (list x y 0))(cons 70 64)))
  14. (entmake (list (cons 0 "VERTEX")(cons 10 (list x 0 0))(cons 70 64)))
  15. (entmake (list (cons 0 "VERTEX")(cons 10 (list x y z))(cons 70 64)))
  16. (entmake (list (cons 0 "VERTEX")(cons 10 (list x y z))(cons 70 64)))
  17. (entmake (list (cons 0 "VERTEX")(cons 10 (list x 0 z))(cons 70 64)))
  18. (entmake (list (cons 0 "VERTEX")(cons 10 (list 0 y z))(cons 70 64)))
  19. (entmake (list (cons 0 "VERTEX")(cons 10 (list 0 y z))(cons 70 64)))
  20. (entmake (list (cons 0 "VERTEX")(cons 10 (list 0 0 z))(cons 70 64)))
  21. (entmake (list (cons 0 "SEQEND")))
  22.  

You could change the order of any of the header values save group 0.

Simply change to x y & z values as needed

I wouldn't want to try making this on a command sequence.

Have fun!  -David

R12 Dos - A2K

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.