Jump to content

Trouble executing commands in lisp


AdamW

Recommended Posts

I am trying to create a routine that allows me to select a dimension that then sets this as the current dimension style and also the current layer from the dimension selected. Code Below

 

(defun C:SetDimLayer ()
  (princ "\Select Desired Dimstyle...")
  (setq sg (ssget))
  (command "-DIMSTYLE" "_R" sg) ;remove this line and line below works
  (command "laymcur" sg) ;remove this line and line above works  
  (princ)
)

I can get this to work with either of the command statements on their own but not with both command lines. Is there something that I am missing.

Link to comment
Share on other sites

Try this quick code:

(defun c:foo (/ e)
 (cond
   ((and (setq e (car (entsel "\nPick a dimension: "))) (= "DIMENSION" (cdr (assoc 0 (entget e)))))
    (setvar 'clayer (cdr (assoc 8 (entget e))))
    (command "-dimstyle" "r" (cdr (assoc 3 (entget e))))
   )
 )
 (princ)
)

Link to comment
Share on other sites

Many Thanks Ron. Jut got to work and tried it out and it works great. Can you tell me what the assoc values are or point me in the direction to find documentation. Im relatively new to new lisp. I have gained most my knowledge from a collegue at work and reverse engineering to see what things do. This assoc is new to me though Ta

Link to comment
Share on other sites

Autocad use dxf codes also known as association values, there is lots of full DXF code lists out there search here 1st. Its basicly the core data base identifying an object by a Unique key.

 

a few common ones but note they can be a bit mixed and match depending on the type of object
10 insert pt, start pt line etc 
11 end pt line etc
8 layer see above
0 object type see above
2 name

 

 

The other thing to use is dumpit.lsp it will reveal a lot of the values and you can use VL-get & put functions re an object properties.

 

;;;===================================================================; 
;;; DumpIt                                                            ; 
;;;-------------------------------------------------------------------; 
;;; Dump all methods and properties for selected objects              ; 
;;;===================================================================; 
(defun C:DumpIt ( / ent) 
 (while (setq ent (entsel)) 
   (vlax-Dump-Object 
     (vlax-Ename->Vla-Object (car ent)) 
   ) 
 ) 
 (princ) 
)

 

Command: DUMPIT

Select object:
; IAcadDimRotated: AutoCAD Rotated Dimension Interface
; Property values:
;   Measurement (RO) = 301.245
;   ObjectName (RO) = "AcDbRotatedDimension"
;   StyleName = "DESIGN"

Link to comment
Share on other sites

HERE is the documentation from the help file too.

 

Also, here is a quick function you can use to inspect items in your drawings.

(defun c:dxf (/ e)
 (cond	((setq e (car (entsel "\nPick something to see DXF data: ")))
 (mapcar 'print (entget e '("*")))
)
 )
 (princ)
)

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