guitarguy1685 Posted February 12, 2010 Posted February 12, 2010 hello again. I'm continuing to try to learn how to create/modify entities through DXF codes. I was trying to write a lisp to create a circle with it's center based on user input. This is what I tried first (defun C:UA () (setq CPT (getpoint "\nSpecify insertion point: ")) (entmake '((0 . "CIRCLE") (8 . "TEST") ([color=Red]10 CPT)[/color] (40 0.375))) ) I got a DXF error on group 10. I first thought well maybe it was because CPT would return ( x y z ) with parenthesis while the group should be (10 x y z) not (10 (x y z) ) so next i tried (defun C:UA () (setq CPT (getpoint "\nSpecify insertion point: ")) (entmake '((0 . "CIRCLE") (8 . "TEST") (10 (car CPT) (cdr CPT) (cddr CPT)) (40 0.375))) ) i still get the same issue. what am I missing? Quote
CarlB Posted February 12, 2010 Posted February 12, 2010 since not all data is literal, can't use a quoted list. Try: (entmake (list '(0 . "CIRCLE") '(8 . "TEST") (cons 10 CPT) '(40 0.375))) Quote
The Buzzard Posted February 12, 2010 Posted February 12, 2010 hello again. I'm continuing to try to learn how to create/modify entities through DXF codes. I was trying to write a lisp to create a circle with it's center based on user input. This is what I tried first (defun C:UA () (setq CPT (getpoint "\nSpecify insertion point: ")) (entmake '((0 . "CIRCLE") (8 . "TEST") ([color=red]10 CPT)[/color] (40 0.375))) ) I got a DXF error on group 10. I first thought well maybe it was because CPT would return ( x y z ) with parenthesis while the group should be (10 x y z) not (10 (x y z) ) so next i tried (defun C:UA () (setq CPT (getpoint "\nSpecify insertion point: ")) (entmake '((0 . "CIRCLE") (8 . "TEST") (10 (car CPT) (cdr CPT) (cddr CPT)) (40 0.375))) ) i still get the same issue. what am I missing? You did not need to use car, getpoint returns the x, y & z values. To use variables in your list you need to use cons. (defun C:UA (/ CPT) (setq CPT (getpoint "\nSpecify insertion point: ")) (entmake (list (cons 0 "CIRCLE") (cons 8 "TEST") (cons 10 CPT) (cons 40 0.375) ) ) (princ)) A little extra when you decide to go there: Set your layer & linetype defaults. Creates the linetype definition HIDDEN2. (Note: If you are using continuous linetype you do not need a linetype definition.) Create a layer called CIRCLE. Layer color red. Linetype HIDDEN2. Lineweight 25mm. Get the radius & center point. Put the Circle on the layer. (defun C:UA2 (/ CPT RAD LNAM LTYP LWGT LCLR) ;Define function, Declare local variables (setq LNAM "CIRCLE" ;Set layer name LCLR 1 ;Set layer color LTYP "HIDDEN2" ;Set linetype LWGT 25) ;Set lineweight (or (tblsearch "ltype" "HIDDEN2") ;Search drawing for linetype (entmake ;Entity make (list ;Start list (cons 0 "LTYPE") ;Entity type (cons 100 "AcDbSymbolTableRecord") ;Subclass marker (cons 100 "AcDbLinetypeTableRecord") ;Subclass marker (cons 2 "HIDDEN2") ;Linetype name (cons 70 0) ;Standard flag values (bit-coded values) (cons 3 "Hidden2 (.5x) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ");Linetype description (cons 72 65) ;Alignment code; value is always 65, the ASCII code for A (cons 73 2) ;The number of linetype elements (cons 40 0.1875) ;Total pattern length (cons 49 0.125) ;Dash, dot or space length (one entry per element) (cons 74 0) ;Complex linetype element type (one per element). Default is 0 (no embedded shape/text) (cons 49 -0.0625) ;Dash, dot or space length (one entry per element) (cons 74 0) ;Complex linetype element type (one per element). Default is 0 (no embedded shape/text) ) ;End list ) ;End entity make ) ;End or (if (null (tblsearch "layer" LNAM)) ;Search drawing for layer name (entmake ;Entity make (list ;Start list (cons 0 "LAYER") ;Entity type (cons 100 "AcDbSymbolTableRecord") ;Subclass marker (cons 100 "AcDbLayerTableRecord") ;Subclass marker (cons 2 LNAM) ;Layer Name (cons 6 LTYP) ;Linetype (cons 62 LCLR) ;Layer color (cons 70 0) ;Layer state (cons 290 1) ;Plotting flag (cons 370 LWGT) ;Set lineweight ) ;End list ) ;End entity make ) ;End if (setq RAD (getreal "\nSpecify radius: ") ;Get Radius CPT (getpoint "\nSpecify circle center point: ")) ;Get center point (entmake ;Entity Make (list ;Start list (cons 0 "CIRCLE") ;Entity type (cons 100 "AcDbEntity") ;Subclass marker (cons 410 "Model") ;Model Space (cons 8 LNAM) ;Layer (cons 100 "AcDbCircle") ;Subclass marker (cons 10 CPT) ;Center point (cons 40 RAD) ;Radius ) ;End list ) ;End Entity make (princ)) ;Exit quietly Quote
The Buzzard Posted February 12, 2010 Posted February 12, 2010 From the Acad developer help: cons Function Adds an element to the beginning of a list, or constructs a dotted list (cons new-first-element list-or-atom) Arguments new-first-element Element to be added to the beginning of a list. This element can be an atom or a list. list-or-atom A list or an atom. Return Values The value returned depends on the data type of list-or-atom. If list-or-atom is a list, cons returns that list with new-first-element added as the first item in the list. If list-or-atom is an atom, cons returns a dotted pair consisting of new-first-element and list-or-atom. Examples Command: (cons 'a '(b c d)) (A B C D) Command: (cons '(a) '(b c d)) ((A) B C D) Command: (cons 'a 2) (A . 2) Here is an interesting Thread on Entity Make for blocks showing the use of cons. http://www.cadtutor.net/forum/showthread.php?t=36793&highlight=entmake+blocks Quote
Lee Mac Posted February 12, 2010 Posted February 12, 2010 Hi Guitar guy, Your question has probably already been answered, but this is definitely worth a read for future: http://www.cadtutor.net/forum/showpost.php?p=258390&postcount=20 Quote
Recommended Posts
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.