Jump to content

Insert Object with Entmake


The Buzzard

Recommended Posts

  • Replies 77
  • Created
  • Last Reply

Top Posters In This Topic

  • The Buzzard

    42

  • Lee Mac

    17

  • David Bethel

    5

  • alanjt

    5

Here's one that makes life a lot easier. You guys will probably have to update it cause it only understands R12 native entities.

 

Basically you create all of the entities you want ( blocked or not ) in a dwg, run this and it exports the entity data in entmake format ( either in quote or list format ) to an ASCII text file with a .emk file extension. Then you can add that right to your autolisp file

 

I use upgrades versions of this daily ( in that they allow variable x y & z inputs ) It is a great time and error saver. Good Luck -David

 

( I made this public domain a long time ago so it's really not new. )

 

 

Watch out for linetypes and textstyles because they must exist prior to calling entmake

EXEMK.LSP

Link to comment
Share on other sites

David,

 

That programs great. I was able to duplicate the lists for the door in this program. It cannot get any easier.

 

See below:

 

A list created with EXEMK.lsp

 

(entmake (list (cons 0 "BLOCK")(cons 2 "LDR")(cons 70 2)(cons 10 (list 0 0 0))))
(entmake (list (cons 0 "LWPOLYLINE")(cons 100 "AcDbEntity")(cons 67 0)(cons 8 "0")(cons 100 "AcDbPolyline")(cons 90 4)(cons 70 1)(cons 43 0)(cons 38 0)(cons 39 0)(cons 10 (list 0 36))(cons 40 0)(cons 41 0)(cons 42 0)(cons 10 (list 2 36))(cons 40 0)(cons 41 0)(cons 42 0)(cons 10 (list 2 0))(cons 40 0)(cons 41 0)(cons 42 0)(cons 10 (list 0 0))(cons 40 0)(cons 41 0)(cons 42 0)(cons 210 (list 0 0 1))(cons 62 256)(cons 6 "BYLAYER")))
(entmake (list (cons 0 "ARC")(cons 100 "AcDbEntity")(cons 67 0)(cons 8 "0")(cons 100 "AcDbCircle")(cons 10 (list 0 0 0))(cons 40 36)(cons 210 (list 0 0 1))(cons 100 "AcDbArc")(cons 50 0)(cons 51 1.5708)(cons 62 256)(cons 39 0)(cons 6 "BYLAYER")))
(entmake (list (cons 0 "ATTDEF")(cons 100 "AcDbEntity")(cons 67 0)(cons 8 "A-DOOR-IDEN")(cons 100 "AcDbText")(cons 10 (list 12 -9 0))(cons 40 4.5)(cons 1 "D01")(cons 50 0)(cons 41 1)(cons 51 0)(cons 7 "Romans")(cons 71 0)(cons 72 1)(cons 11 (list 18 -6.75 0))(cons 210 (list 0 0 1))(cons 100 "AcDbAttributeDefinition")(cons 3 "Door ID:")(cons 2 "ID")(cons 70 (cons 73 0)(cons 74 2)(cons 62 256)(cons 39 0)(cons 6 "BYLAYER")))
(entmake (list (cons 0 "ENDBLK")))
(entmake (list (cons 0 "INSERT")(cons 100 "AcDbEntity")(cons 67 0)(cons 410 "Model")(cons 8 "0")(cons 100 "AcDbBlockReference")(cons 66 1)(cons 2 "LDR")(cons 10 (list 0 0 0))(cons 41 1)(cons 42 1)(cons 43 1)(cons 50 0)(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 100 "AcDbEntity")(cons 67 0)(cons 410 "Model")(cons 8 "A-DOOR-IDEN")(cons 100 "AcDbText")(cons 10 (list 12 -9 0))(cons 40 4.5)(cons 1 "D01")(cons 50 0)(cons 41 1)(cons 51 0)(cons 7 "Romans")(cons 71 0)(cons 72 1)(cons 11 (list 18 -6.75 0))(cons 210 (list 0 0 1))(cons 100 "AcDbAttribute")(cons 2 "ID")(cons 70 (cons 73 0)(cons 74 2)(cons 62 256)(cons 39 0)(cons 6 "BYLAYER")))
(entmake (list (cons 0 "SEQEND")(cons 100 "AcDbEntity")(cons 67 0)(cons 410 "Model")(cons 8 "0")))

Link to comment
Share on other sites

Here's one that makes life a lot easier. You guys will probably have to update it cause it only understands R12 native entities.

 

David,

 

Not sure if I understand you correctly about the R12 native entities.

I ran this code in versions 2004 and 2009 to make the enitity list for the door block with attributes. I turned them into simple functions and it was flawless. It recreated the block with no modifications.

 

Are you refering to entities such as Tables and Dynamic blocks which were not part of R12 as an example?

 

So code may need to be updated for these type of entities?

 

Thanks,

The Buzzard

Link to comment
Share on other sites

To be honest, I didn't think it would pick up the LWPOLYLINE. Maybe because it is nested in a BLOCK, it didn't know any better and just processed it anyway.

 

I'll have to look into it and see. Anyway, glad it worked. -David

Link to comment
Share on other sites

Here is a version that should work with LWPOLYLINES, MTEXT, MLINE, and ELLIPSEs 3DSOLIDS are probably wouldn't work cause of the binary values in group1 -David

EXEMK.LSP

Link to comment
Share on other sites

David,

 

Only one thing I have noticed with your code as the same with the previous.

When running your code on a block in 2009 and inserting the block in 2009 it is OK, When you use the code created with 2009 and inserting a block with the 2009 code into 2004 you get this message: Invalid field type 280 in (entmake).

So I remove the (cons 280 0) from the attributes and the code will work fine in 2004.

 

When you do the opposite by creating the code in 2004, the line (cons 280 0) is not in the code. The new code works fine in both 2004 as well as 2009.

 

I am not sure what it is about although I am aware of this because of the Invalid field type message, I at least know where to look. Must be some quirk caused by 2009. As you may already know 2009 is buggy.

 

My guess is that if using 2004, I should not see a problem in a created code and can expect it to run in future versions. If I run your code in 2009, I will need to check for these Field messages in older versions of ACAD.

 

I thought you should be aware of this. I do not think there is a problem with your code. I believe it is just a 2009 issue.

 

Anyway thanks, Your code is fantastic.

The Buzzard

Link to comment
Share on other sites

Buzzard,

 

Backward compatibility has always been an issue with this kind stuff.

 

I have no idea what group 280 values contains. My guess is that it didn't exist in 2004, so yes you should get an error.

 

There have been many additions to the DXF group codes since R12. I don't have the 100 sub entities, group 60 visibility flag, nothing between 75 and 210 and nothing beyond that.

 

That's why I guess that was surprised that it ran at all. I'm sure that I started this program in the '90s and it's kind of hung there ever since.

 

Glad it worked out. -David

Link to comment
Share on other sites

I just think that no matter what you program, You need to always check it in other versions. A hard lesson for me to have learned.

 

But your program is a real time saver just the same.

I will get alot of use from it.

 

Thanks

Link to comment
Share on other sites

For anyones information Here is what I found on entity code 280 for ACAD 2009:

 

Attdef:

 

Duplicate record cloning flag (determines how to merge duplicate entries):

1 = Keep existing

 

Attrib:

 

Lock position flag. Locks the position of the attribute within the block reference

Link to comment
Share on other sites

  • 1 year later...

Thank you Alan for this code::) (page 3 of this thread)

 

 

;;; Insert block into drawing
;;; #Name - name of block
;;; #InsPt - insert point
;;; #XScale - block X scale
;;; #YScale - block Y scale
;;; #Rot - block rotation
;;; Alan J. Thompson, 04.21.09
(defun AT:InsertBlock (#Name #InsPt #XScale #YScale #Rot)
 (if (or (tblsearch "block" #Name)
         (findfile #Name)
     ) ;_ or
   (vla-insertblock
     ((if (eq (getvar "cvport") 1)
        vla-get-paperspace
        vla-get-modelspace
      ) ;_ if
       (vla-get-ActiveDocument
         (vlax-get-acad-object)
       ) ;_ vla-get-ActiveDocument
     )
     (vlax-3d-point #InsPt)
     #Name
     #XScale
     #YScale
     #XScale
     #Rot
   ) ;_ vla-insert-block
 ) ;_ if
) ;_ defun

Link to comment
Share on other sites

Thank you Alan for this code::) (page 3 of this thread)

 

You're welcome, but that's an old sub before I learned about the inefficiencies of defining the active document and space more really needed.

Try this one...

(defun AT:Insert (space block ins x y r / b)
 ;; Insert specified block into drawing
 ;; space - activespace (model or paper)
 ;; block - name of block
 ;; ins   - insertion point (must be WCS)
 ;; x     - X scale
 ;; y     - Y scale
 ;; r     - rotation
 ;; Alan J. Thompson, 12.10.09
 (if (and (or (tblsearch "BLOCK" block) (setq block (findfile block)))
          (not (vl-catch-all-error-p
                 (setq b (vl-catch-all-apply
                           (function vla-InsertBlock)
                           (list space (vlax-3d-point ins) block x y x r)
                         )
                 )
               )
          )
     )
   b
 )
)

With this for activespace:

(defun AT:ActiveSpace (/)
 ;; Defined ActiveSpace
 ;; Alan J. Thompson, 10.12.09
 (vlax-get-property
   (cond (*AcadDoc*)
         ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
   )
   (if (eq 1 (getvar 'cvport))
     'PaperSpace
     'ModelSpace
   )
 )
)

Link to comment
Share on other sites

I just tried your new code but I can't seem to make it work right - doesn't insert blocks:

(setq space AT:ActiveSpace)
(AT:Insert space Nme pt_Pt 25 25 0)
 

..though I'm able to insert blocks using :

 

(vl-cmdf "_.insert" Nme "_s" 25 pt_Pt 0)

The entire lisp (makes a block - inserts and adds additional text) is below:

(defun c:pt()
(vl-load-com)  
(SETQ CLY (GETVAR "CLAYER"))
(SETQ OSM (GETVAR "OSMODE"))
(SETQ OTM (GETVAR "ORTHOMODE"))
(setq dimzin (getvar 'DIMZIN))
(setvar 'DIMZIN 0)
(setvar "clayer" "RH_FRUTTI")
;
 (defun AT:Insert (space block ins x y r / b)
 ;; Insert specified block into drawing
 ;; space - activespace (model or paper)
 ;; block - name of block
 ;; ins   - insertion point (must be WCS)
 ;; x     - X scale
 ;; y     - Y scale
 ;; r     - rotation
 ;; Alan J. Thompson, 12.10.09
 (if (and (or (tblsearch "BLOCK" block) (setq block (findfile block)))
          (not (vl-catch-all-error-p
                 (setq b (vl-catch-all-apply
                           (function vla-InsertBlock)
                           (list space (vlax-3d-point ins) block x y x r)
                         )
                 )
               )
          )
     )
   b
 )
)

(defun AT:ActiveSpace (/)
 ;; Defined ActiveSpace
 ;; Alan J. Thompson, 10.12.09
 (vlax-get-property
   (cond (*AcadDoc*)
         ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
   )
   (if (eq 1 (getvar 'cvport))
     'PaperSpace
     'ModelSpace
   )
 )
)
;
 (defun LWPoly (lst)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 0)) ;cur fit vertices
             (mapcar (function (lambda (p) (cons 10 p))) lst))))

;
 (defun Line (pt1 pt2);draw line
 (entmakex (list (cons 0 "LINE")
                 (cons 10 pt1)
                 (cons 11 pt2))))


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

 (setq edit4 "test" edit5 "5") ; this is actually returned from user input - DCL dialog
 

 (cond ((= EDIT5 "4") (setq radiusPT (/ 0.154 2) Nme "D-4" tft 0.5)) ; raggio // block name // txt height factor
   ((= EDIT5 "5") (setq radiusPT (/ 0.154 2) Nme "D-5" tft 0.6))
       ((= EDIT5 "6") (setq radiusPT (/ 0.195 2) Nme "D-6" tft 0.7))
   ((= EDIT5 "7") (setq radiusPT (/ 0.287 2) Nme "D-7" tft 0.)
   ((= EDIT5 "8") (setq radiusPT (/ 0.391 2) Nme "D-8" tft 0.9))
   ((= EDIT5 "9") (setq radiusPT (/ 0.479 2) Nme "D-9" tft 1.0))
   ((= EDIT5 "10") (setq radiusPT (/ 0.515 2)Nme "D-10" tft 1.0))
 );cond

(setq profon (/ 0.069 2) pt0 '(0 0 0))

(setq    p1 (list (- radiusPT) (- profon)) ; for solid points 
   p2 (list (- radiusPT) profon)
   p3 (list radiusPT profon)
   p4 (list radiusPT (- profon)))

 (setq L1 0.02
   ptl1 (list (- (+ radiusPT L1)) 0)
   ptl2 (list (+ radiusPT L1) 0)
   ptl3 (list 0 (+ profon L1))
   ptl4 (list 0 (- (+ profon L1))))

  ;(defun CreatBlock (BlkNme)
 (entmake (list (cons 0 "BLOCK")
     (cons 100 "AcDbEntity")
     (cons 67 0)
     (cons 8  "0")
     (cons 100 "AcDbBlockReference")
     (cons 2 Nme)
     (cons 10 pt0)
     (cons 70 0)
    )
 )

 (solid p1 p2 p4 p3)
 (line ptl1 ptl2)
 (line ptl3 ptl4)
 (LWPoly (list p1 p2 p3 p4 p1))

(entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
(setq pt_Pt(getpoint "\n Insertion point: "))

(setq space AT:ActiveSpace)
(AT:Insert space Nme pt_Pt 25 25 0)
 
;(vl-cmdf "_.insert" Nme "_s" 25 pt_Pt 0);


 (setq x1(car pt_Pt))                              [get x coordinate of pt_Pt]
 (setq y1(cadr pt_Pt))                             [get y coordinate of pt_Pt]
 (setq pt_cntr (list x1 y1))
 (setq x2 (- x1 (* 0.1 tft)))
 (setq y2 (- y1 (* 0.08 tft) ))
 (setq d_text_pt (list x2 y2))

(and ; inserisce nome pt
      (entmakex
    (list
      '(0 . "MTEXT")
      '(100 . "AcDbEntity")
      '(100 . "AcDbMText")
       ;(cons 8 "RH_FRUTTI")
      (cons 1 (strcase Edit4)) ; nome pt
      ;(cons 7 (getvar 'textstyle))
      (cons 10 d_text_pt)
      (cons 40 (* tft 0.1))        ;sets text height
    ) ;_ list
      ) ;_ entmakex
 ) ;_ and

(setq tipo_pt (strcat "PT" Edit5))
 
 (and ; inserisce tipo pt
      (entmakex
    (list
      '(0 . "MTEXT")
      '(100 . "AcDbEntity")
      '(100 . "AcDbMText")
       (cons 8 "RH_FRUTTI")
      (cons 1 tipo_pt ); tipo pt
      ;(cons 7 (getvar 'textstyle))
      (cons 10 pt_cntr)
      (cons 40 0.02)        ;sets text height
    ) ;_ list
      ) ;_ entmakex
 ) ;_ and

(SETVAR "CLAYER" CLY)
(SETVAR "OSMODE" OSM)
(SETVAR "ORTHOMODE" OTM)
(setvar 'DIMZIN dimzin)  

 );defun
 (princ)

All help is appreciated.

Edited by sadhu
typos correction
Link to comment
Share on other sites

You aren't calling the activespace sub correctly...

 

eg.

(AT:Insert (AT:ActiveSpace) Nme pt_Pt 25 25 0)

or

(setq space (AT:ActiveSpace))
(AT:Insert space Nme pt_Pt 25 25 0)

Link to comment
Share on other sites

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...