Jump to content

Change DIM style by pressing down a key


Abrasive

Recommended Posts

I'm not sure if it's possible but...

I use 4 DIM styles almost exclusively.

What I would like to do is start a command that activates a specific DIM style, (then measure distance)

Press a key and change DIM style, activate "continue DIM" and use the new style for this function.

Press a different key, change to a different DIM style then activate "continue DIM" again and use the new style for this function.

Finally press a 4th key, change to a different DIM style and NOT activate "continue DIM" ( just activate specific DIM style ).

One problem I had is when changing dim style and activating continue it uses the previous style instead of the new one.

I tried a couple of things but made a mess of it...lol

Any help would be appreciated.

Thank you

 

Link to comment
Share on other sites

Let us have a look at what you have put together, you might be close with what you have.

Link to comment
Share on other sites

Are you using the same series of styles every time? For instance, the first dimension is always Style1, the second is Style2, and so on. That would make the function easier to write.

 

If not, you could use a loop, get a style based on user input of a key, and use a cond statement to set the style based on the input. That way the style can change each time, and you can cycle through the loop as many times as you like. Another option is an association list containing dotted pairs, each with a key and a style name; each time the style changes, use the input to look up the name.

Link to comment
Share on other sites

Posted (edited)

@CyberAngel I am using the same styles every time, and in the same order.

@Steven P the routines I have only change the dimension style by running the routine.

 

I tried to figure out how to use keys to activate them but couldn't find much... 

(defun c:CDS8EA ( ) 
  (command "Layer" "M" "FINAL MEAS" "")
  (command "-dimstyle" "R" "8 ALN END ARROW")  
  (command "_LINEARDIMENSION")  
)

 

Edited by Abrasive
Link to comment
Share on other sites

I Have a pan macro base on what number pad key I press affected what direction it would pan. very helpful for grid layouts I did. I'll post it later.

Link to comment
Share on other sites

Maybe something like this? Change the Dimstyle names in the (cond) statement to match your dimension styles. You can also change the wording between the "[...]" in the getpoint prompt as long as you keep the "1-, 2-." etc. on the front of each option. You could also change the default option to "Exit" if you change the option in the "<...>" of the prompt and the code line (if (not p1)(setq p1 "1")) to "Exit" as well.

;;Written by PJK 8/6/2024
(defun C:LDIM (/ p1)
   (initget "1 2 3 4 Exit")
   (while
      (and
         (/= (type (setq p1 (getpoint "\nSelect first point for Linear Dimension or [1-Style1/2-Style2/3-Style3/4-Style4/Exit] <1-Style1>: "))) 'LIST)
         (/= p1 "Exit")
      )
      (if (not p1)(setq p1 "1"))
      (cond
         ((= p1 "1")(command "._-dimstyle" "_r" "MyDimStyle1"));; Change Dim Style Names to Your preferences.
         ((= p1 "2")(command "._-dimstyle" "_r" "MyDimStyle2"))
         ((= p1 "3")(command "._-dimstyle" "_r" "MyDimStyle3"))
         ((= p1 "4")(command "._-dimstyle" "_r" "MyDimStyle4"))
      )
      (initget "1 2 3 4 Exit")
   )
   (if (= (type p1) 'LIST)
      (progn
         (command "._dimlinear" p1)
         (while (= (logand (getvar "cmdactive") 1) 1)
      		(command pause)
      	)
      )
   )
   (princ)
)

 

  • Like 1
Link to comment
Share on other sites

My $0.05 i would use defun names like S1 S2 etc very short to type, you can also have dim styles in a pop menu. 

 

image.png.82def2e1a7c6c68c4451d34d6e489c82.png

 

 

Link to comment
Share on other sites

So its pretty simple using grread to run sub commands allowing you to switch between the four different types. kinda follows the same principles of pkenewell's code. except its four smaller lisps called from one main lisp. if you wanted to use other buttons you would have to look them up. I think those are for the numpad keys.

 

(defun c:CDS8EA () 
  (entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "FINAL MEAS") (70 . 0) (62 . 1) (290 . 0))) ;change 62 to the coler you want
  (setvar 'clayer "FINAL MEAS")
  (command "-dimstyle" "R" "8 ALN END ARROW")  
  (while (setq pt (getpoint))
    (command "_.LINEARDIMENSION" pt)  
    (while (= (getvar "cmdactive") 1)
      (command pause)
    )
  )
)
(defun C:MyDims (/ *error* P thisdrawing)
  (defun *error* ()
    (vl-cmdf nil nil nil) ;clear 
    (if (not (member *error* '("Console break" "Function cancelled" "quit / exit abort")))
      (princ (strcat "\nError: " errmsg))
    )
    (setvar 'cmdecho 1)
  )
  (setvar 'cmdecho 0)
  (setq P T)
  (setq thisdrawing (vla-get-activedocument (vlax-get-acad-object)))
  (prompt "\nUse Enter to Exit")
  (while P
    (while (/= (car (setq key (grread))) 2))
    (setq key (cadr key))
    (cond
      ((= key 49)            ;#1 key
        (C:CDS8EA)           
      )
      ((= key 50)            ;#2 key
      )
      ((= key 51)            ;#3 key
      )
      ((= key 52)            ;#4 key
      )
      ((= key 53)            ;#5 key
      )
      ((= key 54)            ;#6 key
      )
      ((= key 55)            ;#7 key
      )
      ((= key 56)            ;#8 key
      )
      ((= key 57)            ;#9 key
      )
      ((= key 13)            ;#Enter key
        (setq P nil)
      )
    )
  )
  (setvar 'cmdecho 1)
  (princ)
)

 

 

  • Like 2
Link to comment
Share on other sites

Didn't have time for this one yesterday, but I'd have gone grread and perhaps see if the arrow keys would work

Link to comment
Share on other sites

Thank you everyone!

@mhupp I really like the use of grread, @pkenewell 's code worked well too.

 

These will get me where I need.

@BIGAL As always thank you. I am trying to avoid using DCL for this one, I'm getting lazy and just want to hit a key a few hundred time a day....lol

 

Thanks Again.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

4 hours ago, Steven P said:

Didn't have time for this one yesterday, but I'd have gone grread and perhaps see if the arrow keys would work

 

looks like arrow keys are 37-40

I only used the numpad with that command but according to this its 96-105 maybe grread defaults to both ?

  • Like 1
Link to comment
Share on other sites

@Abrasive still think S1 s2 is about as simple as it gets, popping the dcl can be very fast I use my Multi radio buttons. The 1st time is a little slow as it loads but from then on is fast. It can be set to remember last used so just hit enter or pick. Try it. Easy to add more choices.

 

(if (not AH:Butts)(load "Multi radio buttons.lsp")) 			; loads the program if not loaded already
(if (= defbut nil)(setq defbut 1)) 					; this is needed to set default button
(setq ans (ah:butts defbut "V"   '("Choose Dim style " "Dim style A" "Dim style B" "Dim style C" "Dim style D" ))) 	; ans holds the button picked value as a string
(setq defbut but)

 

image.png.728f98cf4d4cc3796726037e7f0c6370.pngMulti radio buttons.lsp

 

 

Edited by BIGAL
  • Like 1
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...