Jump to content

Assign Certain Layer to a Toolbar


TimZilla

Recommended Posts

I made a custom toolbar. On this toolbar I put a Polyline tool. When I click this I want it to automatically put the polyline in the assigned layer.

 

Is this possible? :)

Link to comment
Share on other sites

  • Replies 34
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    14

  • gazzalp

    11

  • Raggi_Thor

    3

  • TimZilla

    3

yes, what did you put in the button? I ask to help you put this ahead of it. A few questions, do you want a macro or LISP solution? If macro, add -layer;s;YourLayerNameHere;;YourPolylinemacroGoesHere

 

If you use LISP, you can capture what layer your on now, switch layers, draw the polyline, and switch back.

 

If you use palettes, you can do the same thing w/o the code

Link to comment
Share on other sites

yes, what did you put in the button? I ask to help you put this ahead of it. A few questions, do you want a macro or LISP solution? If macro, add -layer;s;YourLayerNameHere;;YourPolylinemacroGoesHere

 

If you use LISP, you can capture what layer your on now, switch layers, draw the polyline, and switch back.

 

If you use palettes, you can do the same thing w/o the code

 

 

ok, if i go to tools/workspaces/customize/toolbars and then to my custom toolbar I am making.

 

inside those options I see a macro option and when I open the box to edit it it says

 

"^C^C_pline"

 

what would I need to add to that. Im new to this sort of thing.

Link to comment
Share on other sites

yes, what did you put in the button? I ask to help you put this ahead of it. A few questions, do you want a macro or LISP solution? If macro, add -layer;s;YourLayerNameHere;;YourPolylinemacroGoesHere

 

If you use LISP, you can capture what layer your on now, switch layers, draw the polyline, and switch back.

 

If you use palettes, you can do the same thing w/o the code

 

 

ok I got it figured out, thanks!

Link to comment
Share on other sites

That macro also helps me. One question, sometimes our layers go missing, so for example i want to put a dimension on the dimension layer, but there wont be one yet. So when i click on dimension it tries to automatically put it on dimension but cant find it. Is there a way i can make it make the layer "dimension"?

Link to comment
Share on other sites

Thanks, one more thing; is there a way that when that macro has been used the current layer will go back to what it was originally. IE: if im on layer 0, and use a dimension, it puts the layer on dimension, but also changes my current layer from 0 to dimension.

Link to comment
Share on other sites

one more thing; is there a way that when that macro has been used the current layer will go back to what it was originally. IE: if im on layer 0, and use a dimension, it puts the layer on dimension, but also changes my current layer from 0 to dimension.

 

Wouldn't all this be easier accomplished using LISP?

 

(defun c:dimtest (/ oldlay oldcmd)
   (setq oldlay (getvar "clayer"))
   (setq oldcmd (getvar "cmdecho"))
   (setvar "cmdecho" 0)
   (if    (not (tblsearch "Layer" "Dimension"))
   (command "-layer" "m" "Dimension" "")
   (setvar "clayer" "Dimension")
   ) ;_  end if
   (command "_dimlinear")
   (while (> (getvar "cmdactive") 0) (command pause))
   (setvar "clayer" oldlay)
   (setvar "cmdecho" oldcmd)
   (princ)
) ;_  end defun

Just send a call from the toolbar to the loaded LISP

Link to comment
Share on other sites

Possibly, but even though youve given me the lisp for dimensions, i still have continue dimensions, hatch, text, viewports etc to do, and i already owe you a case of beer, i cant afford much more :P

Link to comment
Share on other sites

layer;m;"dimension";;

 

should work...

 

I tried that, but what it does is bring up the layers (im guessing so i can add one). What id rather is have it add the dimension layer by itself, and then put the dimension on "dimension" is this possible?

 

Also still hoping someone knows a way of making the layer go back to the orginal once the item is inserted, instead of having a lisp routine for all the things i want changed (hatch, dimension, continue dimension, viewport, text)

Link to comment
Share on other sites

I tried that, but what it does is bring up the layers (im guessing so i can add one). What id rather is have it add the dimension layer by itself, and then put the dimension on "dimension" is this possible?

 

Try this:

 

-layer;"m";"Dimension";;

Link to comment
Share on other sites

Possibly, but even though youve given me the lisp for dimensions, i still have continue dimensions, hatch, text, viewports etc to do, and i already owe you a case of beer, i cant afford much more :P

 

I understand where you're coming from, but I'm not sure how you could accomplish resetting the layer with tapping into LISP - but maybe someone has already figured out a way to do it.

 

If you want to continue the LISP way - the posted LISP can be very easily modified to suit most commands.

Link to comment
Share on other sites

Another thought - why not just use a reactor?

 

This is the reactor I posted on another thread - it will automatically change the current layer to a specific layer, then after the command has ended, or been aborted, the original current layer will return.

 

 ; Layer Director by Lee McDonnell

(vl-load-com)

(vlr-command-reactor
   nil
   '((:vlr-commandWillstart . startCommand))
) ; end command reactor
(vlr-command-reactor
   nil
   '((:vlr-commandEnded . endcommand))
) ; end command reactor
(vlr-command-reactor
   nil
   '((:vlr-commandCancelled . cancelCommand))
) ; end command reactor

(defun startCommand (calling-reactor startcommandInfo / thecommandstart)
   (setq oldlay (getvar "clayer"))
   (setq thecommandstart (nth 0 startcommandInfo))
   (cond
   ((= thecommandstart "TEXT")
    (setvar "clayer" "TEXT")
   ) ; end condition 1
   ((= thecommandstart "MTEXT")
    (setvar "clayer" "TEXT")
   ) ; end condition 2
   ((= thecommandstart "DTEXT")
    (setvar "clayer" "TEXT")
   ) ; end condition 3

 ;        ---------------------------

   ((= thecommandstart "DIMLINEAR")
    (setvar "clayer" "DIM")
   ) ; end condition 4
   ((= thecommandstart "DIMALIGNED")
    (setvar "clayer" "DIM")
   ) ; end condition 5
   ((= thecommandstart "DIMRADIUS")
    (setvar "clayer" "DIM")
   ) ; end condition 6
   ((= thecommandstart "DIMDIAMETER")
    (setvar "clayer" "DIM")
   ) ; end condition 7
   ((= thecommandstart "DIMANGULAR")
    (setvar "clayer" "DIM")
   ) ; end condition 8
   ((= thecommandstart "DIMORDINATE")
    (setvar "clayer" "DIM")
   ) ; end condition 9

 ;        ---------------------------

   ((= thecommandstart "+VPORTS")
    (setvar "clayer" "DEFPOINTS")
   ) ; end condition 10
   ) ; end cond
   (princ)
) ; end startcommand

(defun endCommand (calling-reactor endcommandInfo / thecommandend)
   (setq thecommandend (nth 0 endcommandInfo))
   (cond
   ((= thecommandend "TEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 1
   ((= thecommandend "MTEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 2
   ((= thecommandend "DTEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 3

 ;        ---------------------------

   ((= thecommandend "DIMLINEAR")
    (setvar "clayer" oldlay)
   ) ; end condition 4
   ((= thecommandend "DIMALIGNED")
    (setvar "clayer" oldlay)
   ) ; end condition 5
   ((= thecommandend "DIMRADIUS")
    (setvar "clayer" oldlay)
   ) ; end condition 6
   ((= thecommandend "DIMDIAMETER")
    (setvar "clayer" oldlay)
   ) ; end condition 7
   ((= thecommandend "DIMANGULAR")
    (setvar "clayer" oldlay)
   ) ; end condition 8
   ((= thecommandend "DIMORDINATE")
    (setvar "clayer" oldlay)
   ) ; end condition 9

 ;        ---------------------------

   ((= thecommandend "+VPORTS")
    (setvar "clayer" oldlay)
   ) ; end condition 10

   ) ; end cond
   (princ)
) ; end endCommand

(defun cancelCommand (calling-reactor cancelcommandInfo / thecommandcancel)
   (setq thecommandcancel (nth 0 cancelcommandInfo))
   (cond
   ((= thecommandcancel "TEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 1
   ((= thecommandcancel "MTEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 2
   ((= thecommandcancel "DTEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 3

 ;        ---------------------------

   ((= thecommandcancel "DIMLINEAR")
    (setvar "clayer" oldlay)
   ) ; end condition 4
   ((= thecommandcancel "DIMALIGNED")
    (setvar "clayer" oldlay)
   ) ; end condition 5
   ((= thecommandcancel "DIMRADIUS")
    (setvar "clayer" oldlay)
   ) ; end condition 6
   ((= thecommandcancel "DIMDIAMETER")
    (setvar "clayer" oldlay)
   ) ; end condition 7
   ((= thecommandcancel "DIMANGULAR")
    (setvar "clayer" oldlay)
   ) ; end condition 8
   ((= thecommandcancel "DIMORDINATE")
    (setvar "clayer" oldlay)
   ) ; end condition 9

 ;        ---------------------------

   ((= thecommandcancel "+VPORTS")
    (setvar "clayer" oldlay)
   ) ; end condition 10

   ) ; end cond
   (princ)
) ; end cancelCommand

(defun makelay (lay / oldlay)
   (if    (not (tblsearch "LAYER" lay))
   (progn
       (setq oldlay (getvar "clayer"))
       (setvar "cmdecho" 0)
       (command "-layer" "m" lay "")
       (setvar "cmdecho" 1)
       (setvar "clayer" oldlay)
   ) ;_  end progn
   ) ;_  end if
) ;_  end defun

(mapcar 'makelay '("TEXT" "DIM" "DEFPOINTS"))

 

The above can be modifed to suit different layer structures.

Link to comment
Share on other sites

As with lisps, im not very familiar with reactors. Ill try that reactor out, but how do i use it? IE how do i set it to work for lets say single line text? Remember i have no idea how it works, so i need to know how to load it, if i save it like i do with lisps etc. Thanks Lee

Link to comment
Share on other sites

As with lisps, im not very familiar with reactors. Ill try that reactor out, but how do i use it? IE how do i set it to work for lets say single line text? Remember i have no idea how it works, so i need to know how to load it, if i save it like i do with lisps etc. Thanks Lee

 

With the reactor, save it to a notepad doc (.lsp), just like a LISP, and just load it on ACAD start-up. As its a reactor, it has no syntax to type - it runs automatically.

 

You may need it modified to suit your layer structure, but experiment with it and see if its something you want to use.

Link to comment
Share on other sites

Looks good Lee. One request, could you also add Hatch to that please? i only use the single hatch command, and i want it on a layer called "Hatch"

Link to comment
Share on other sites

Also Lee, i have found after i do a viewport, it doesnt change the layer back to the original state. Ill play around with it myself and hopefully fix it, but if not could you have a look at it please?

Link to comment
Share on other sites

Lee, ive used my absolutely superior skills to figure out how to do the hatch myself :P. I owe everything to you though :P One problem is i see youve added the ability to add the layers if they are not present in the DWG, i tried literally adding in the words "hatch" where i thought it would go so it works for hatch as well, but for some reason it doesnt. Also when it makes the "Text" layer could we somehow set it to the colour yellow not the white that comes up? so my 3 problems are:

 

1. Hatch layer wont be added to drawing if not there already.

2. Text layer change to yellow.

3. Defpoints not changing to old layer when viewport has been put on.

 

This is my code:

  ; Layer Director by Lee McDonnell
(vl-load-com)
(vlr-command-reactor
   nil
   '((:vlr-commandWillstart . startCommand))
) ; end command reactor
(vlr-command-reactor
   nil
   '((:vlr-commandEnded . endcommand))
) ; end command reactor
(vlr-command-reactor
   nil
   '((:vlr-commandCancelled . cancelCommand))
) ; end command reactor
(defun startCommand (calling-reactor startcommandInfo / thecommandstart)
   (setq oldlay (getvar "clayer"))
   (setq thecommandstart (nth 0 startcommandInfo))
   (cond
   ((= thecommandstart "TEXT")
    (setvar "clayer" "TEXT")
   ) ; end condition 1
   ((= thecommandstart "MTEXT")
    (setvar "clayer" "TEXT")
   ) ; end condition 2
   ((= thecommandstart "DTEXT")
    (setvar "clayer" "TEXT")
   ) ; end condition 3
 ;        ---------------------------
   ((= thecommandstart "DIMLINEAR")
    (setvar "clayer" "DIMENSIONS")
   ) ; end condition 4
   ((= thecommandstart "DIMALIGNED")
    (setvar "clayer" "DIMENSIONS")
   ) ; end condition 5
   ((= thecommandstart "DIMRADIUS")
    (setvar "clayer" "DIMENSIONS")
   ) ; end condition 6
   ((= thecommandstart "DIMCONTINUE")
    (setvar "clayer" "DIMENSIONS")
   ) ; end condition 7
   ((= thecommandstart "DIMANGULAR")
    (setvar "clayer" "DIMENSIONS")
   ) ; end condition 8
   ((= thecommandstart "QLEADER")
    (setvar "clayer" "DIMENSIONS")
   ) ; end condition 9
 ;        ---------------------------

   ((= thecommandstart "BHATCH")
    (setvar "clayer" "HATCH")
   ) ; end condition 11
 ;        ---------------------------
   ((= thecommandstart "+VPORTS")
    (setvar "clayer" "DEFPOINTS")
   ) ; end condition 10
   ) ; end cond
   (princ)
) ; end startcommand
(defun endCommand (calling-reactor endcommandInfo / thecommandend)
   (setq thecommandend (nth 0 endcommandInfo))
   (cond
   ((= thecommandend "TEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 1
   ((= thecommandend "MTEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 2
   ((= thecommandend "DTEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 3
 ;        ---------------------------
   ((= thecommandend "DIMLINEAR")
    (setvar "clayer" oldlay)
   ) ; end condition 4
   ((= thecommandend "DIMALIGNED")
    (setvar "clayer" oldlay)
   ) ; end condition 5
   ((= thecommandend "DIMRADIUS")
    (setvar "clayer" oldlay)
   ) ; end condition 6
   ((= thecommandend "DIMCONTINUE")
    (setvar "clayer" oldlay)
   ) ; end condition 7
   ((= thecommandend "DIMANGULAR")
    (setvar "clayer" oldlay)
   ) ; end condition 8
   ((= thecommandend "QLEADER")
    (setvar "clayer" oldlay)
   ) ; end condition 9
   ((= thecommandend "BHATCH")
    (setvar "clayer" oldlay)
   ) ; end condition 11
 ;        ---------------------------
   ((= thecommandend "+VPORTS")
    (setvar "clayer" oldlay)
   ) ; end condition 10
   ) ; end cond
   (princ)
) ; end endCommand
(defun cancelCommand (calling-reactor cancelcommandInfo / thecommandcancel)
   (setq thecommandcancel (nth 0 cancelcommandInfo))
   (cond
   ((= thecommandcancel "TEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 1
   ((= thecommandcancel "MTEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 2
   ((= thecommandcancel "DTEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 3
 ;        ---------------------------
   ((= thecommandcancel "DIMLINEAR")
    (setvar "clayer" oldlay)
   ) ; end condition 4
   ((= thecommandcancel "DIMALIGNED")
    (setvar "clayer" oldlay)
   ) ; end condition 5
   ((= thecommandcancel "DIMRADIUS")
    (setvar "clayer" oldlay)
   ) ; end condition 6
   ((= thecommandcancel "DIMCONTINUE")
    (setvar "clayer" oldlay)
   ) ; end condition 7
   ((= thecommandcancel "DIMANGULAR")
    (setvar "clayer" oldlay)
   ) ; end condition 8
   ((= thecommandcancel "QLEADER")
    (setvar "clayer" oldlay)
   ) ; end condition 9
   ((= thecommandcancel "BHATCH")
    (setvar "clayer" oldlay)
   ) ; end condition 11
 ;        ---------------------------
   ((= thecommandcancel "+VPORTS")
    (setvar "clayer" oldlay)
   ) ; end condition 10
   ) ; end cond
   (princ)
) ; end cancelCommand
(defun makelay (lay / oldlay)
   (if    (not (tblsearch "LAYER" lay))
   (progn
       (setq oldlay (getvar "clayer"))
       (setvar "cmdecho" 0)
       (command "-layer" "m" lay "")
       (setvar "cmdecho" 1)
       (setvar "clayer" oldlay)
   ) ;_  end progn
   ) ;_  end if
) ;_  end defun
(mapcar 'makelay '("TEXT" "Dimensions" "DEFPOINTS"))xt" "Dimensions" "Defpoints"))

Link to comment
Share on other sites

1. Hatch layer wont be added to drawing if not there already.
I have updated the LISP to include this.

 

2. Text layer change to yellow.
Again, LISP has been updated to include this.

 

3. Defpoints not changing to old layer when viewport has been put on.
I don't seem to have this trouble: I go to View>Viewports>New Viewport> then I draw the viewport and upon finishing drawing my viewport, the layer will revert back to the original.

 

Anyway, try this:

 

 ; Layer Director by Lee McDonnell

 ; V1.1 Hatch, QLeader Commands Added, Layer Construction Updated.

(vl-load-com)

(vlr-command-reactor
   nil
   '((:vlr-commandWillstart . startCommand))
) ; end command reactor
(vlr-command-reactor
   nil
   '((:vlr-commandEnded . endcommand))
) ; end command reactor
(vlr-command-reactor
   nil
   '((:vlr-commandCancelled . cancelCommand))
) ; end command reactor

(defun startCommand (calling-reactor startcommandInfo / thecommandstart)
   (setq oldlay (getvar "clayer"))
   (setq thecommandstart (nth 0 startcommandInfo))
   (cond
   ((= thecommandstart "TEXT")
    (setvar "clayer" "TEXT")
   ) ; end condition 1
   ((= thecommandstart "MTEXT")
    (setvar "clayer" "TEXT")
   ) ; end condition 2
   ((= thecommandstart "DTEXT")
    (setvar "clayer" "TEXT")
   ) ; end condition 3

 ;        ---------------------------

   ((= thecommandstart "DIMLINEAR")
    (setvar "clayer" "Dimensions")
   ) ; end condition 4
   ((= thecommandstart "DIMALIGNED")
    (setvar "clayer" "Dimensions")
   ) ; end condition 5
   ((= thecommandstart "DIMRADIUS")
    (setvar "clayer" "Dimensions")
   ) ; end condition 6
   ((= thecommandstart "DIMDIAMETER")
    (setvar "clayer" "Dimensions")
   ) ; end condition 7
   ((= thecommandstart "DIMANGULAR")
    (setvar "clayer" "Dimensions")
   ) ; end condition 8
   ((= thecommandstart "DIMORDINATE")
    (setvar "clayer" "Dimensions")
   ) ; end condition 9
   ((= thecommandstart "QLEADER")
    (setvar "clayer" "Dimensions")
   ) ; end condition 10

 ;        ---------------------------

   ((= thecommandstart "+VPORTS")
    (setvar "clayer" "DEFPOINTS")
   ) ; end condition 11

 ;        ---------------------------

   ((= thecommandstart "BHATCH")
    (setvar "clayer" "HATCH")
   ) ; end condition 12
   ) ; end cond
   (princ)
) ; end startcommand

(defun endCommand (calling-reactor endcommandInfo / thecommandend)
   (setq thecommandend (nth 0 endcommandInfo))
   (cond
   ((= thecommandend "TEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 1
   ((= thecommandend "MTEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 2
   ((= thecommandend "DTEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 3

 ;        ---------------------------

   ((= thecommandend "DIMLINEAR")
    (setvar "clayer" oldlay)
   ) ; end condition 4
   ((= thecommandend "DIMALIGNED")
    (setvar "clayer" oldlay)
   ) ; end condition 5
   ((= thecommandend "DIMRADIUS")
    (setvar "clayer" oldlay)
   ) ; end condition 6
   ((= thecommandend "DIMDIAMETER")
    (setvar "clayer" oldlay)
   ) ; end condition 7
   ((= thecommandend "DIMANGULAR")
    (setvar "clayer" oldlay)
   ) ; end condition 8
   ((= thecommandend "DIMORDINATE")
    (setvar "clayer" oldlay)
   ) ; end condition 9
   ((= thecommandend "QLEADER")
    (setvar "clayer" oldlay)
   ) ; end condition 10

 ;        ---------------------------

   ((= thecommandend "+VPORTS")
    (setvar "clayer" oldlay)
   ) ; end condition 11

 ;        ---------------------------

   ((= thecommandend "BHATCH")
    (setvar "clayer" oldlay)
   ) ; end condition 12
   ) ; end cond
   (princ)
) ; end endCommand

(defun cancelCommand (calling-reactor cancelcommandInfo / thecommandcancel)
   (setq thecommandcancel (nth 0 cancelcommandInfo))
   (cond
   ((= thecommandcancel "TEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 1
   ((= thecommandcancel "MTEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 2
   ((= thecommandcancel "DTEXT")
    (setvar "clayer" oldlay)
   ) ; end condition 3

 ;        ---------------------------

   ((= thecommandcancel "DIMLINEAR")
    (setvar "clayer" oldlay)
   ) ; end condition 4
   ((= thecommandcancel "DIMALIGNED")
    (setvar "clayer" oldlay)
   ) ; end condition 5
   ((= thecommandcancel "DIMRADIUS")
    (setvar "clayer" oldlay)
   ) ; end condition 6
   ((= thecommandcancel "DIMDIAMETER")
    (setvar "clayer" oldlay)
   ) ; end condition 7
   ((= thecommandcancel "DIMANGULAR")
    (setvar "clayer" oldlay)
   ) ; end condition 8
   ((= thecommandcancel "DIMORDINATE")
    (setvar "clayer" oldlay)
   ) ; end condition 9
   ((= thecommandcancel "QLEADER")
    (setvar "clayer" oldlay)
   ) ; end condition 10

 ;        ---------------------------

   ((= thecommandcancel "+VPORTS")
    (setvar "clayer" oldlay)
   ) ; end condition 11

 ;        ---------------------------

   ((= thecommandcancel "BHATCH")
    (setvar "clayer" oldlay)
   ) ; end condition 12
   ) ; end cond
   (princ)
) ; end cancelCommand

(defun makelay (lay / oldlay)
   (if    (not (tblsearch "LAYER" lay))
   (progn
       (setq oldlay (getvar "clayer"))
       (setvar "cmdecho" 0)
       (command "-layer" "m" lay "")
       (setvar "cmdecho" 1)
       (setvar "clayer" oldlay)
   ) ;_  end progn
   ) ;_  end if
) ;_  end defun

(mapcar 'makelay '("Dimensions" "DEFPOINTS" "HATCH"))

(if (not (tblsearch "LAYER" "TEXT"))
   (progn
   (setq oldlayer (getvar "clayer"))
   (setvar "cmdecho" 0)
   (command "-layer" "m" "TEXT" "c" "2" "TEXT" "")
   (setvar "cmdecho" 1)
   (setvar "clayer" oldlayer)
   ) ;_  end progn
) ;_  end if

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