Tool Palette offset, match or draw options

Tool Palette offset, match or draw options

jbott
Contributor Contributor
1,063 Views
8 Replies
Message 1 of 9

Tool Palette offset, match or draw options

jbott
Contributor
Contributor

I know it can be done i have used it before but i dont know much about macros

I need a button on palette that give me the ability to when picked ask the user to either "o" offset, "d draw pl, or "m" match properties.

the button will be a certain layer that when i choose offset whatever line i pick and offset from it will change to the "certain layer"

that would be the same for draw and match properties.

0 Likes
Accepted solutions (1)
1,064 Views
8 Replies
Replies (8)
Message 2 of 9

ВeekeeCZ
Consultant
Consultant

Try this lisp. You need save it as *.lsp, store in your support path, use _APPLOAD, store it it the suitcase and then assign to your Tool Palette's command just 

 

ODM;

 

(defun C:ODM ( / *error* oCLAYER doc cmd) ;Offset - Draw a polyline - Match layer

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'CLAYER oCLAYER)
    (vla-endundomark doc)
    (princ)
  )

  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (setq oCLAYER (getvar 'CLAYER))
  (command "_.-LAYER" "_M" "Name of your certain layer" "") ;<- rename this!
  (initget "Offset Draw Match")
  (setq cmd (getkword "\nSelect command [Offset/Draw-pl/Match-layer] <match-layer>: "))
  (cond ((= "Offset" cmd)
	 (command "_.OFFSET" "_L" "_C"))
	((= "Draw" cmd)
	 (command "_.PLINE"))
	(T
	 (command "_.LAYCUR")))
  (while (> (getvar 'CMDACTIVE) 0)
	   (command PAUSE))
  (setvar 'CLAYER oCLAYER)
  (vla-endundomark doc)
  (princ)
)

 

0 Likes
Message 3 of 9

jbott
Contributor
Contributor

thank you for your response,

how do i get that on a palette for the users?

i could have 20 different layers that the user will need to pick from palette to be able to do that comand  (odm)

do i call it out as a macro? then lisp? how would the macro look in the palette properties

0 Likes
Message 4 of 9

ВeekeeCZ
Consultant
Consultant

Hi, I modified the code little bit. Layer is now handled by ToolPalette property. Also is able a window selection for Match-Layer.

 

Spoiler
(defun C:ODM ( / *error* oCLAYER doc cmd)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (vla-endundomark doc)
    (princ)
  )

  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (initget "Offset Draw Match")
  (setq cmd (getkword "\nSelect command [Offset/Draw-pl/Match-layer] <match-layer>: "))
  (cond ((= "Offset" cmd)
	 (command "_.OFFSET" "_L" "_C")
	 (while (> (getvar 'CMDACTIVE) 0)
	   (command PAUSE)))
	((= "Draw" cmd)
	 (command "_.PLINE")
	 (while (> (getvar 'CMDACTIVE) 0)
	   (command PAUSE)))
	(T
	 (command "_.SELECT")
	 (while (> (getvar 'CMDACTIVE) 0)
	   (command PAUSE))
	 (command "_.LAYCUR" "_P" ""
		  "_.SETBYLAYER" "_P" "" "_N" "_N")))
  (vla-endundomark doc)
  (princ)
)

Add new botton on ToolPalette, in Properties set "Command string" to ODM; and change Layer (see screenshot).

Edit: One more improvement.

0 Likes
Message 5 of 9

jbott
Contributor
Contributor

IT WORKS PERFECT THANK YOU

 

Is there a way to default last command used? for example if i choose "o" = offest when i go back into command it is defaulted to offest tell i choose a different comannd then default that one and so on.

 

 

0 Likes
Message 6 of 9

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, you have that as multiple as I could... and under <enter> option is your last choice. Your first default is "Match-layer" (red), if you want to change it, you have blueones to pick.

 

Spoiler
(defun C:ODM ( / *error* doc pt ss) ; GLOBAL VARIABLES: #cmd

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (vla-endundomark doc)
    (princ)
  )

  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (initget "Offset Draw-pl Match-layer")
  (setq #cmd (cond ((getkword (strcat "\nSelect command [Offset/Draw-pl/Match-layer] <" (cond (#cmd) ("Match-layer")) ">: ")))
		   (#cmd)
		   ("Match-layer")))
  (cond ((= "Offset" #cmd)
	 (command "_.OFFSET" "_L" "_C")
	 (while (> (getvar 'CMDACTIVE) 0)
	   (command PAUSE)))
	((= "Draw-pl" #cmd)
	 (while (setq pt (getpoint "\nSpecify start point: "))
	   (command "_.PLINE" pt)
	   (while (> (getvar 'CMDACTIVE) 0)
	     (command PAUSE))
	   (princ "\nPress enter for <EXIT>, ")))
	(T
	 (while (setq ss (ssget))
	   (command "_.LAYCUR" ss ""
		    "_.SETBYLAYER" "_P" "" "_N" "_N")
	   (princ "\nPress enter for <EXIT>, "))
	 ))

  (vla-endundomark doc)
  (princ)
)

Have fun!

0 Likes
Message 7 of 9

jbott
Contributor
Contributor

is there away in the code to use the last command as default?

 

I know its set to match as default but if i pick offset then when i go into the command again the default will be offset

0 Likes
Message 8 of 9

ВeekeeCZ
Consultant
Consultant
It works like that inside one drawing. But not across drawings... is that what you want?
0 Likes
Message 9 of 9

jbott
Contributor
Contributor

BeekeeCZ your amazing works exacatly like requested.

 

Smiley Very Happy

0 Likes