Author Topic: ENTMAKE function  (Read 38586 times)

0 Members and 2 Guests are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28685
ENTMAKE function
« on: April 18, 2005, 09:34:34 AM »
Using 'entmake'. Is there something in the docs that can tell me what the minimum requirements are for a given entity when using this function?

Take the 'line' entity for example;
Code: [Select]

(
 (-1 . <Entity name: 7efecb10>)
 (0 . "LINE")
 (330 . <Entity name: 7ef8fd18>)
 (5 . "33BA")
 (100 . "AcDbEntity")
 (67 . 0)
 (410 . "Model")
 (8 . "0")
 (100 . "AcDbLine")
 (10 512691.0 1.3465e+006 0.0)
 (11 512455.0 1.3465e+006 0.0)
 (210 0.0 0.0 1.0)
 )

How much of the above do I *need* in order to create a line!
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17446
ENTMAKE function
« Reply #1 on: April 18, 2005, 10:24:51 AM »
For all objects lose the -1, 5 and 330 groups.

For lines lose the 100 groups.

IIRC 8, 67, and 410 are optional but a good idea (will default to current space etc).

Entity types addded to AutoCAD 13 and later require the 100 groups, for example mtext.

Thus, this should work:

Code: [Select]
(entmake
   '(
        (0 . "LINE")
        (10 512691.0 0.0 0.0)
        (11 512455.0 0.0 0.0)
        (210 0.0 0.0 1.0)
    )
)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Mark

  • Custom Title
  • Seagull
  • Posts: 28685
ENTMAKE function
« Reply #2 on: April 18, 2005, 10:37:53 AM »
Thank MP. Can I assume then we have to use the values that are not listed as optional. Take the TEXT DXF code for example.
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17446
ENTMAKE function
« Reply #3 on: April 18, 2005, 10:49:58 AM »
Not necessarilly, as that listing does not identify the subclasss groups (100) as optional.

I would add that it doesn't hurt to include the 100 groups or any other 'optional groups'. Moreover, I believe it makes your intent clearer (yep, put this on layer "DIMS") and finally, there may be the day when entmake is not as casual about its requirements.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

CADaver

  • Guest
ENTMAKE function
« Reply #4 on: April 18, 2005, 10:50:39 AM »
Oh, another opportunity for education... Minimum info for ENTMAKE.

In another thread we're talking about a routine for making text styles and layers.  Maybe some gure here could "SIMPLY" explain ENTMAKE, and maybe how to entmake elements.

MP

  • Seagull
  • Posts: 17446
ENTMAKE function
« Reply #5 on: April 18, 2005, 10:53:54 AM »
Well ... if one doesn't show up I'll be happy to pen a thread on this, but it won't be until this evening. I'll show how to entmake a block definition and then a subsequent insert of said def, c/w attributes on specific layers with specific styles. That should cover most of the bases.

If I've the time I'll also provide equivalent activex code. Yeah, I like that idea.

:)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

CADaver

  • Guest
ENTMAKE function
« Reply #6 on: April 18, 2005, 11:10:21 AM »
Quote from: MP
Well ... if one doesn't show up I'll be happy to pen a thread on this, but it won't be until this evening. I'll show how to entmake a block definition and then a subsequent insert of said def, c/w attributes on specific layers with specific styles. That should cover most of the bases.

If I've the time I'll also provide equivalent activex code. Yeah, I like that idea.

:)
cool, I'll be waitin'

Mark

  • Custom Title
  • Seagull
  • Posts: 28685
ENTMAKE function
« Reply #7 on: April 18, 2005, 11:13:40 AM »
Quote from: MP

Not necessarilly, as that listing does not identify the subclasss groups (100) as optional.

Exactly, meaning we should use them because they're not listed as optional, even though they are.
Quote from: MP

I would add that it doesn't hurt to include the 100 groups or any other 'optional groups'. Moreover, I believe it makes your intent clearer (yep, put this on layer "DIMS") and finally, there may be the day when entmake is not as casual about its requirements.

No argument there. *grin*
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28685
ENTMAKE function
« Reply #8 on: April 18, 2005, 11:17:48 AM »
Quote from: CADaver

In another thread we're talking about a routine for making text styles and layers...

umm ... coincidental 8)
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
ENTMAKE function
« Reply #9 on: April 18, 2005, 11:51:16 AM »
I have some examples but would pale to anything Michael would come up with.
This is something I have been using for some time.

Code: [Select]
; here's a thing that can make entmakes of almost anything pulled from a drawing:
;; correction by CAB 11/19/04 - did not remove douplicate codes
;; CAB added removal of 100 410 210


(defun C:makeEntmake (/ a dwg path ent entl fn sset)
  (setq path (getvar "DWGPREFIX")
        dwg  (strcat path (vl-filename-base (getvar "DWGNAME")) ".lsp")
        fn   (open dwg "w")
        a    0
  )
  (cond
    (fn
     (cond ((setq sset (ssget))
            (repeat (sslength sset)
              (setq ent  (ssname sset a)
                    entl (entget ent)
              )
  (foreach n '(-2 -1 5 102 300 330 331 350 360 100 410 210); 100 410 210
    (while (assoc n entl)
      (setq entl (vl-remove (assoc n entl) entl))
    )
  )
              (write-line (strcat "(entmake '" (vl-prin1-to-string entl) ")") fn)
              (setq a (1+ a))
            )
           )
     )
     (close fn)
    )
  )
  (princ)
)
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.

David Bethel

  • Swamp Rat
  • Posts: 641
ENTMAKE function
« Reply #10 on: April 18, 2005, 11:52:44 AM »
These are what I have on the older native entities.

6 defualts to CELTYPE
8 defaults to CLAYER
39 deaults to THICKNESS
62 defaults to CECOLOR
210 deaults to '(0 0 1)

48 defaults to CELTSCALE

text attdef 11 is not always required but a good habit to use  Make 11 = 10 when in doubt.

Code: [Select]

;*** = required field in (entmake)

(entmake (list (cons 0 "3DFACE") ;***
               (cons 6 "BYLAYER")
               (cons 8 "0")
               (cons 10 (list 0.0 0.0 0.0)) ;***
               (cons 11 (list 1.0 0.0 0.0)) ;***
               (cons 12 (list 0.0 1.0 0.0)) ;***
               (cons 13 (list 1.0 1.0 0.0)) ;***
               (cons 39 0.0)
               (cons 62 256)
               (cons 70 0)))

(entmake (list (cons 0 "ARC") ;***
               (cons 6 "BYLAYER")
               (cons 8 "0")
               (cons 10 (list 0.0 0.0 0.0)) ;***
               (cons 39 0.0)
               (cons 40 1.0) ;***
               (cons 50 0.0) ;***
               (cons 51 1.57079633) ;***
               (cons 62 256)
               (cons 210 (list 0.0 0.0 1.0))))

(entmake (list (cons 0 "ATTDEF") ;***
               (cons 8 "0")
               (cons 10 (list 0 0 0)) ;***
               (cons 40 1) ;***
               (cons 1 "") ;***
               (cons 3 "") ;***
               (cons 2 "TEST") ;***
               (cons 70 0)
               (cons 73 0)
               (cons 50 0)
               (cons 41 1)
               (cons 51 0)
               (cons 7 "STANDARD") ;***
               (cons 71 0)
               (cons 72 0)
               (cons 11 (list 0 0 0)) ;***
               (cons 210 (list 0 0 1))
               (cons 74 0)
               (cons 62 256)
               (cons 39 0)
               (cons 6 "BYLAYER")))

(entmake (list (cons 0 "CIRCLE") ;***
               (cons 6 "BYLAYER")
               (cons 8 "0")
               (cons 10 (list 0.0 0.0 0.0)) ;***
               (cons 39 0.0)
               (cons 40 1.0) ;***
               (cons 62 256)
               (cons 210 (list 0.0 0.0 1.0))))

(entmake (list (cons 0 "INSERT") ;***
               (cons 2 "LEG6") ;***
               (cons 6 "BYLAYER")
               (cons 8 "0")
               (cons 10 (list 0.0 0.0 0.0)) ;***
               (cons 39 0.0)
               (cons 41 1.0)
               (cons 42 1.0)
               (cons 43 1.0)
               (cons 44 0.0)
               (cons 45 0.0)
               (cons 50 0.0)
               (cons 62 256)
               (cons 70 0)
               (cons 71 0)
               (cons 210 (list 0.0 0.0 1.0))))

(entmake (list (cons 0 "INSERT") ;***
               (cons 8 "0")
               (cons 66 1) ;***
               (cons 2 "CPD") ;***
               (cons 10 (list 0 0 0)) ;***
               (cons 41 1)
               (cons 42 1)
               (cons 50 0)
               (cons 43 1)
               (cons 70 0)
               (cons 71 0)
               (cons 44 0)
               (cons 45 0)
               (cons 210 (list 0 0 1))
               (cons 62 256)
               (cons 39 0)
               (cons 6 "BYLAYER")))
(entmake (list (cons 0 "ATTRIB") ;***
               (cons 8 "0")
               (cons 10 (list 0 0 0)) ;***
               (cons 40 1) ;***
               (cons 1 "TESTING 123") ;***
               (cons 2 "TAGNAME") ;***
               (cons 70 0)
               (cons 73 0)
               (cons 50 0)
               (cons 41 1)
               (cons 51 0)
               (cons 7 "STANDARD") ;***
               (cons 71 0)
               (cons 72 0)
               (cons 11 (list 0 0 0)) ;***
               (cons 210 (list 0 0 1))
               (cons 74 0)
               (cons 62 256)
               (cons 39 0)
               (cons 6 "BYLAYER")))
(entmake (list (cons 0 "SEQEND") ;***
               (cons 8 "0")))

(entmake (list (cons 0 "LINE") ;***
               (cons 6 "BYLAYER")
               (cons 8 "0")
               (cons 10 (list 0.0 0.0 0.0)) ;***
               (cons 11 (list 0.0 1.0 0.0)) ;***
               (cons 39 0.0)
               (cons 62 256)
               (cons 210 (list 0.0 0.0 1.0))))

(entmake (list (cons 0 "POLYLINE") ;***
               (cons 6 "BYLAYER")
               (cons 8 "0")
               (cons 10 (list 0.0 0.0 0.0)) ;***
               (cons 39 0.0)
               (cons 40 0.0)
               (cons 41 0.0)
               (cons 62 256)
               (cons 66 1)
               (cons 70 0)
               (cons 71 0)
               (cons 72 0)
               (cons 73 0)
               (cons 74 0)
               (cons 75 0)
               (cons 210 (list 0.0 0.0 1.0))))
(entmake (list (cons 0 "VERTEX") ;***
               (cons 6 "BYLAYER")
               (cons 8 "0")
               (cons 10 (list 0.0 0.0 0.0)) ;***
               (cons 39 0.0)
               (cons 40 0.0)
               (cons 41 0.0)
               (cons 42 0.0)
               (cons 50 0.0)
               (cons 70 0)
               (cons 71 0)
               (cons 72 0)
               (cons 73 0)
               (cons 74 0)
               (cons 62 256)))
(entmake (list (cons 0 "VERTEX") ;***
               (cons 6 "BYLAYER")
               (cons 8 "0")
               (cons 10 (list 1.0 0.0 0.0)) ;***
               (cons 39 0.0)
               (cons 40 0.0)
               (cons 41 0.0)
               (cons 42 0.0)
               (cons 50 0.0)
               (cons 70 0)
               (cons 71 0)
               (cons 72 0)
               (cons 73 0)
               (cons 74 0)
               (cons 62 256)))
(entmake (list (cons 0 "SEQEND") ;***
               (cons 8 "0")))

(entmake (list (cons 0 "POINT") ;***
               (cons 6 "BYLAYER")
               (cons 8 "0")
               (cons 10 (list 0.0 0.0 0.0)) ;***
               (cons 39 0.0)
               (cons 50 0.0)
               (cons 62 256)
               (cons 210 (list 0.0 0.0 1.0))))

(entmake (list (cons 0 "SOLID") ;***
               (cons 6 "BYLAYER")
               (cons 8 "0")
               (cons 10 (list 0.0 0.0 0.0)) ;***
               (cons 11 (list 1.0 0.0 0.0)) ;***
               (cons 12 (list 0.0 1.0 0.0)) ;***
               (cons 13 (list 1.0 1.0 0.0)) ;***
               (cons 39 0.0)
               (cons 62 256)
               (cons 210 (list 0.0 0.0 1.0))))

(entmake (list (cons 0 "TEXT") ;***
               (cons 1 "") ;***
               (cons 6 "BYLAYER")
               (cons 7 "STANDARD") ;***
               (cons 8 "0")
               (cons 10 (list 0.0 0.0 0.0)) ;***
               (cons 11 (list 0.0 0.0 0.0)) ;***
               (cons 39 0.0)
               (cons 40 1.0) ;***
               (cons 41 1.0)
               (cons 50 0.0)
               (cons 51 0.0)
               (cons 62 256)
               (cons 71 0)
               (cons 72 0)
               (cons 73 0)
               (cons 210 (list 0.0 0.0 1.0))))

(entmake (list (cons 0 "TRACE") ;***
               (cons 6 "BYLAYER") ;***
               (cons 8 "0")
               (cons 10 (list 0.0 0.0 0.0)) ;***
               (cons 11 (list 0.0 1.0 0.0)) ;***
               (cons 12 (list 1.0 0.0 0.0)) ;***
               (cons 13 (list 1.0 1.0 0.0)) ;***
               (cons 39 0.0)
               (cons 62 256)
               (cons 210 (list 0.0 0.0 1.0))))



-David
R12 Dos - A2K

MP

  • Seagull
  • Posts: 17446
ENTMAKE function
« Reply #11 on: April 18, 2005, 12:01:52 PM »
Good stuff David, you should visit more often.

CAB, consider this alternative:

Code: [Select]
(vl-remove-if
   '(lambda (pair)
        (member (car pair)
           '(-2 -1 5 102 300 330 331 350 360 100 210 410)
        )
    )
    entityData
)

:)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
ENTMAKE function
« Reply #12 on: April 18, 2005, 12:15:22 PM »
Thanks MP - code revised.
Very nice David, it is a good start. Let's see what needs to be added. :)
Code: [Select]
;; here's a thing that can make entmakes of almost anything pulled from a drawing:
;; correction by CAB 11/19/04 - did not remove douplicate codes
;; CAB added removal of 100 410 210
;; MP revised removal code

(defun C:makeEntmake (/ a dwg path ent entl fn sset)
  (setq path (getvar "DWGPREFIX")
        dwg  (strcat path (vl-filename-base (getvar "DWGNAME")) ".lsp")
        fn   (open dwg "w")
        a    0
  )
  (cond
    (fn
     (cond ((setq sset (ssget))
            (repeat (sslength sset)
              (setq ent  (ssname sset a)
                    entl (entget ent)
                    entl (vl-remove-if
                            '(lambda (pair)
                                (member (car pair)
                                    '(-2 -1 5 102 300 330 331 350 360 100 210 410)
                                )
                             ) entL
                          )
              )
              (write-line (strcat "(entmake '" (vl-prin1-to-string entl) ")") fn)
              (setq a (1+ a))
            )
           )
     )
     (close fn)
    )
  )
  (princ)
)
(prompt "\nEntity to lisp file loaded, Enter MakeEntitymake to run.")
(princ)
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.

MP

  • Seagull
  • Posts: 17446
ENTMAKE function
« Reply #13 on: April 18, 2005, 01:18:36 PM »
I've resisted the temptation to rewrite your utility Charles (nice one btw) but the way it's written it will strip precision from any reals.

I quickly wrote this (hope there's no errors), which you can incorporate, ignore or critique (or any combo thereof) ...

Code: [Select]
(defun ToString ( x / typex )

    ;;  convert item to a string, if x is a real use
    ;;  the highest possible precision, if x is a
    ;;  string double quote it, if x is a list process
    ;;  each item in the list appropriatel, otherwise
    ;;  just hammer item with vl-princ-to-string

    (cond

        ;;  it's a string, return it double quoted

        (   (eq 'str (setq typex (type x)))

            (strcat "\"" x "\"")

        )

        ;;  it's a real, covert to the highest possible
        ;;  resolution string equivalent

        (   (eq 'real typex)
       
            (rtos x 2 (if (zerop (- x (fix x))) 1 15))

        )

        ;;  it's a list

        (   (eq 'list typex)

            (if (vl-list-length x)

                ;;  it's a normal list

                (strcat
                    (chr 40)
                    (ToString (car x))
                    (apply 'strcat
                        (mapcar
                           '(lambda (x)
                                (strcat " " (ToString x))
                            )
                            (cdr x)
                        )
                    )
                    (chr 41)
                )

                ;;  it's a dotted pair

                (strcat
                    (chr 40)
                    (ToString (car x))
                    " . "
                    (ToString (cdr x))
                    (chr 41)
                )

            )

        )

        ;;  hammer down on everything else

        ((vl-princ-to-string x))
    )
)

Might return a string like --

Code: [Select]
"(  (0 . \"LINE\")
    (67 . 0)
    (8 . 0)
    (10 512538.5490080543 -52.18808513476187 0)
    (11 512606.286451516 -23.08692226341844 0)
)"

Assuming one stripped out non essential group codes first.

While it doesn't preserve the kind of numerical accuracy AutoCAD utilizes internally it's a wee bit better than what you get from a blanket vl-princ-to-string.

:)

Edit 1: Renamed function to 'ToString'.
Edit 2: Return strings double quoted.
Edit 3: Streamlined function.
Edit 4: Strip superfluous zeros
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
ENTMAKE function
« Reply #14 on: April 18, 2005, 01:23:59 PM »
Quote from: MP
I've resisted rewriting your utility Charles but the way it's written it will strip precision from any reals.


I did not originate the routine, just made mods to it.
Any improvements are welcome.
Thanks
CAB
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.