Jump to content

Set current dim style by lisp command


wimal

Recommended Posts

(defun _SetDimStyleCurrent (dim / acdoc)
 (vl-load-com)
 (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
 (if (tblsearch "DIMSTYLE" dim)
   (vla-put-activeDimstyle
     acdoc
     (vla-item (vla-get-Dimstyles acdoc) dim)
   )
 )
 (princ)
)

 

Usage ...

 

(_SetDimStyleCurrent "Standard")

Link to comment
Share on other sites

Use the system variable to retrieve the current dimension style and after that implement my function to reset it back .

 

(setq old-dim (getvar 'dimstyle))

 

(_SetDimStyleCurrent old-dim)

Link to comment
Share on other sites

  • 3 years later...

(vl-load-com)
(defun c:test (/ dxf sym)
      (setq dxf (entget(setq sym (car(entsel)))))
(cond
 ((= (cdr(assoc 0 dxf)) "DIMENSION") (and (_SetDimStyleCurrent (cdr(assoc 3 dxf)))[b][color="red"] (setvar "CLAYER" (cdr(assoc 3 dxf)))[/color][/b] ))
 
 (t nil)
)
 )

 


(defun _SetDimStyleCurrent (dim / acdoc)
 
 (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
 (if (tblsearch "DIMSTYLE" dim)
   (vla-put-activeDimstyle
     acdoc
     (vla-item (vla-get-Dimstyles acdoc) dim)
   )
 )
 (princ)
)

 

error: AutoCAD variable setting rejected: "CLAYER" "dim25

 

why?

Link to comment
Share on other sites

Are you sure that you have a layer name with the same name of Dimension Style name ?

 

If yes, this should work, otherwise layer name won't be set and no error reports should be received.

 

(defun c:test (/ dxf sym sn)
 (if (and (setq sym (car (entsel "\nSelect dimension :")))
          (= (cdr (assoc 0 (setq dxf (entget sym)))) "DIMENSION")
          (setq sn (cdr (assoc 3 dxf)))
          )
   (progn
     (_SetDimStyleCurrent sn)
     (if (tblsearch "LAYER" sn)
       (setvar "CLAYER" sn)
       )
     )
   )
 (princ)
 )

Edited by Tharwat
Link to comment
Share on other sites

Are you sure that you have a layer name with the same name of Dimension Style name ?

 

If yes, this should work, otherwise layer name won't be set and no error reports should be received.

 

(defun c:test (/ dxf sym sn)
 (if (and (setq sym (car (entsel "\nSelect dimension :")))
          (= (cdr (assoc 0 (setq dxf (entget)))) "DIMENSION")
          (setq sn (cdr (assoc 3 dxf)))
          )
   (progn
     (_SetDimStyleCurrent sn)
     (if (tblsearch "LAYER" sn)
       (setvar "CLAYER" sn)
       )
     )
   )
 (princ)
 )

 

thanks

(you forget entget nil)

 

entity selection lanches a command with the same style and layer.

command identity is the same of the select entity type

ive managhed to write solution for dim and polyline

 

2 qestions

1. how can i retrive the last settings after completting the (command "command")

2.how can i clear the command line before applying the (command "command")?

(vl-load-com)
(defun c:test (/ dxf sym prlay prts prdim)
 
 (if(setq sym (car(entsel)))
   (progn
     (setq dxf (entget sym)
           prlay (getvar "CLAYER")
           prts (getvar "TEXTSTYLE")
           prdim (getCurrentDimstyle))
     (setvar "CLAYER" (cdr(assoc 8 dxf)))

     (cond
 	((= (cdr(assoc 0 dxf)) "DIMENSION") (and (_SetDimStyleCurrent (cdr(assoc 3 dxf))) (command "_dimlinear")))
 	((= (cdr(assoc 0 dxf)) "LWPOLYLINE") (command _pline))
 	(t nil)
    )
)
   )
 )
  

(defun _SetDimStyleCurrent (dim / acdoc)
 
 (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
 (if (tblsearch "DIMSTYLE" dim)
   (vla-put-activeDimstyle
     acdoc
     (vla-item (vla-get-Dimstyles acdoc) dim)
   )
 )
 (princ)
)

(defun getCurrentDimstyle (/ acdoc dim n)
 
 (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))
dim (vla-get-activeDimstyle acdoc)
n (vla-get-name dim))
 n
)

Link to comment
Share on other sites

  • 2 years later...

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