Jump to content
wimal

Set current dim style by lisp command

Recommended Posts

wimal

How can I set the current dimension style by LISP:x

Share this post


Link to post
Share on other sites
Tharwat

(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")

Share this post


Link to post
Share on other sites
wimal

Thanks , the code is working nicely.And can you help me to go back to previous dim style without typing the style name.

Share this post


Link to post
Share on other sites
Tharwat

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)

Share this post


Link to post
Share on other sites
wimal

OK THANKS

(setq old-dim (getvar 'dimstyle))
(_SetDimStyleCurrent old-dim)

Share this post


Link to post
Share on other sites
Tharwat
OK THANKS

 

You're welcome .

Share this post


Link to post
Share on other sites
samifox

(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?

Share this post


Link to post
Share on other sites
Tharwat

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

Share this post


Link to post
Share on other sites
samifox
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
)

Share this post


Link to post
Share on other sites
Phani

(command "dimstyle" "r" dim)

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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