Jump to content

Recommended Posts

Posted

That one doesnt seem to work Lee, its not adding the layers if theyre not in the drawing already. Also what you said about viewports is correct, if i do it the way you said it does change the layer back. However i usually use the viewport toolbar (much easier to click one button rather than go into the menu. When i use the button it doesnt work.

  • Replies 34
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    14

  • gazzalp

    11

  • Raggi_Thor

    3

  • TimZilla

    3

Posted

 ; 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 "-VPORTS")
    (setvar "clayer" "DEFPOINTS")
   ) ; end condition 12

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

   ((= thecommandstart "BHATCH")
    (setvar "clayer" "HATCH")
   ) ; end condition 13
   ) ; 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 "-VPORTS")
    (setvar "clayer" oldlay)
   ) ; end condition 12

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

   ((= thecommandend "BHATCH")
    (setvar "clayer" oldlay)
   ) ; end condition 13
   ) ; 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 "-VPORTS")
    (setvar "clayer" oldlay)
   ) ; end condition 12

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

   ((= thecommandcancel "BHATCH")
    (setvar "clayer" oldlay)
   ) ; end condition 13
   ) ; 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

 

This will active the defpoints layer when a viewpoint is drawn, but I can't work out why it won't go back to the original, sorry. :oops:

Posted

Interesting post!

 

Allways use "-layer;m" in stead of "-layer;s", because one day the layer is not there for youand then Make is better than Set.

 

I have sometimes used VBA and different events to set layer, for example in the "BeginCommand" (if I remember correct), se if CommandName is like Dim* and then activate the dim layer. You can also turn off all layers made by SolDraw and SolProf when yiu switch layout to the model tab, or add a dim layer for the current layout. Lots of events that can be used.

Posted

Thanks for your input Raggi - I wish I knew more about reactors, they can be so useful. But I mostly just stick to LISP and haven't even touched on VBA, but I have heard of the BeginCommand mentioned on here before.

Posted

But you know more about the new visual lisp stuff than I do.

You have reactors there also?

 

This is what you get if you navigate to the VB Editor (Shift+F11) and select first AcadDocument and then BeginCommand:

 

Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
                      Debug.Print CommandName
End Sub

 

 

I just typed Debug.Print CommandName

but you can do whatever you want based on what the CommandName is.

Posted

Nice, thats interesting. Thanks.

 

By the way, just out of interest, would you happen to know why my posted reactor does not revert back to the original layer only on the "-VPORT" command call? When all the other command calls function correctly.

Posted

Lee, it doesnt seem to add a text layer. Also how would i go about changing the "hatch" layer that is created to colour 8?

Posted
Lee, it doesnt seem to add a text layer. Also how would i go about changing the "hatch" layer that is created to colour 8?

 

The LISP creates all layers upon loading fine on my machine. I have updated the Hatch layer for you.

 

 ; Layer Director by Lee McDonnell

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

 ; V1.2 Hatch Layer Colour Change.

(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 "-VPORTS")
    (setvar "clayer" "DEFPOINTS")
   ) ; end condition 12

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

   ((= thecommandstart "BHATCH")
    (setvar "clayer" "HATCH")
   ) ; end condition 13
   ) ; 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 "-VPORTS")
    (setvar "clayer" oldlay)
   ) ; end condition 12

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

   ((= thecommandend "BHATCH")
    (setvar "clayer" oldlay)
   ) ; end condition 13
   ) ; 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 "-VPORTS")
    (setvar "clayer" oldlay)
   ) ; end condition 12

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

   ((= thecommandcancel "BHATCH")
    (setvar "clayer" oldlay)
   ) ; end condition 13
   ) ; 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"))

(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

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



Posted

I get this with dimlinear: Command: _dimlinear ; error: AutoCAD variable setting rejected: "clayer" but its happening with all the commands... i dont see how it could be working on yours and not on mine though

Posted
Try this:

 

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

 

Oops. Forgot the "-"...

 

Thanks for covering me!

Posted
Oops. Forgot the "-"...

 

Thanks for covering me!

 

 

No probs - you had the right idea anyway :)

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