Author Topic: Please check my work  (Read 1016 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
Please check my work
« on: February 16, 2021, 03:21:21 PM »
To avoid overrides being permanent I've chosen this path to create a DIMEN layer and start the linear dimension command with 3 overrides for color. Then I want to return the color back to it's original state while eliminating the override.

I started with a snippet from Balaji Ramamoorthy's post on AutoCAD DevBlog - https://adndevblog.typepad.com/autocad/2012/06/overcoming-dimstyle-overrides.html,
and a post from Lee Mac on changing Dimscale using the same method - https://www.theswamp.org/index.php?topic=41211.msg463704#msg463704

All seems to work. I just I want to make sure I haven't missed something or am misunderstanding something. Any critique would be great.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:LimDim ( / curdimstyle curdoc)
  3.  
  4.    ;; Get the current dimstyle
  5.  
  6.    (setq acadApp (vlax-get-acad-object)
  7.          curDoc  (vla-get-ActiveDocument acadApp)
  8.          curDimStyle (vla-get-ActiveDimstyle curDoc)
  9.  
  10.    ) ;setq
  11.  
  12.    ;; Modify the current dimstyle.
  13.    ;; This is done by changing the current dimvars
  14.    ;; and by saving the dimvars in the dimstyle.
  15.    ;; Change a dimvar.
  16.  
  17.    (vla-SetVariable curDoc "DIMCLRE" 1)
  18.    (vla-SetVariable curDoc "DIMCLRT" 1)
  19.    (vla-SetVariable curDoc "DIMCLRD" 1)
  20.  
  21.    ;; Save the current dim vars in the current dim style.
  22.  
  23.    (vla-CopyFrom curDimStyle curDoc)
  24.  
  25.    (command "layer" "make" "DIMEN" "COLOR" "GREEN" "DIMEN" "")
  26.    (command-S "dimlinear" pause pause pause)
  27.    
  28.    (vla-SetVariable curDoc "DIMCLRE" 256)
  29.    (vla-SetVariable curDoc "DIMCLRT" 256)
  30.    (vla-SetVariable curDoc "DIMCLRD" 256)
  31.  
  32.    ;; Save the current dim vars in the current dim style.
  33.  
  34.   (vla-CopyFrom curDimStyle curDoc)
  35.  
  36.    (princ)
  37.  
  38. )
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Please check my work
« Reply #1 on: February 16, 2021, 04:10:58 PM »
Food for thought:
You can also use SETVAR. Something like the following should get you there.

Code - Auto/Visual Lisp: [Select]
  1. (mapcar 'eval '((setvar "DIMCLRE" 1) (setvar "DIMCLRT" 1) (setvar "DIMCLRD" 1)))
  2. (command "_.dimstyle" "s" "MyDimstyle")

Also, you can use PAUSE like this in your lisp code instead of giving a specific number of PAUSE commands.

Code - Auto/Visual Lisp: [Select]
  1. ((lambda nil
  2.   (command-S "dimlinear")
  3.   (while (eq (logand (getvar "CMDACTIVE") 1) 1)
  4.    (command PAUSE))
  5.  ))
  6.  
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org