Author Topic: make layer when xref command is executed  (Read 3965 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
make layer when xref command is executed
« on: October 06, 2004, 12:16:10 PM »
How would you guys go about implementing a layer creation proggie that creates a predetermined layer when a certain command is run?

Example:

Xref is typed into the command line, I want the layer xref to be created and set current so xrefs are inserted on this layer. Do I have to undefine the xref command and redefine it with a lisp that makes the layer then executes the .xref command? If so, how do I make xref command use the dialogue in lisp rather than going to the command line?


Thanks,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

hudster

  • Gator
  • Posts: 2848
make layer when xref command is executed
« Reply #1 on: October 06, 2004, 12:25:02 PM »
I created a macro button which does the same thing.

Code: [Select]
^C^C-layer;make;XREF;c;8;XREF;;xref;
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
make layer when xref command is executed
« Reply #2 on: October 06, 2004, 12:31:27 PM »
Well, you can create a VBA reactor to do just that....

So.. just for you....

Code: [Select]

Dim CLayer As String

Private Sub AcadDocument_Activate()
 CLayer = ""
End Sub

Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
 Dim DLay As AcadLayer
 If CLayer <> "" Then
  ThisDrawing.SetVariable "CLAYER", CLayer
  CLayer = ""
 End If
 If (CommandName = "XREF") Then
  CLayer = ThisDrawing.GetVariable("CLAYER")
  Set DLay = ThisDrawing.Layers.Add("XREF")
  DLay.Color = acCyan
  ThisDrawing.SetVariable "CLAYER", "XREF"
 End If
End Sub

Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
 On Error GoTo EOS
 If CLayer <> "" Then
  ThisDrawing.SetVariable "CLAYER", CLayer
  CLayer = ""
 End If
EOS:
End Sub
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ronjonp

  • Needs a day job
  • Posts: 7529
make layer when xref command is executed
« Reply #3 on: October 06, 2004, 12:58:35 PM »
Keith,

That proggie is great! What do I modify to set the layer back if esc is hit?

Thanks,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
make layer when xref command is executed
« Reply #4 on: October 06, 2004, 02:11:03 PM »
Well, that is the only caveat with reactors. There is not a reactor for ESC and since the VBA program itself did not generate an error, there is no error code catch to tell if the layer needs to be reset.

The command is already set up to return to the previous layer upon the next command issued, if it was reset by the reactor.

Try this.
Set the layer to 0
Issue the XREF command
The layer will now be your XREF layer
Cancel the XREF command
The XREF layer does not change back.
Issue another command...
Before that command is executed the layer returns back to it's original layer.

Cool huh...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ronjonp

  • Needs a day job
  • Posts: 7529
make layer when xref command is executed
« Reply #5 on: October 06, 2004, 03:39:23 PM »
Quote
The command is already set up to return to the previous layer upon the next command issued, if it was reset by the reactor.


That is perfect. Thanks again.  :D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
make layer when xref command is executed
« Reply #6 on: October 06, 2004, 03:41:01 PM »
I do my best...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Andrea

  • Water Moccasin
  • Posts: 2372
make layer when xref command is executed
« Reply #7 on: February 27, 2005, 06:34:32 PM »
Quote from: Keith
Well, you can create a VBA reactor to do just that....

So.. just for you....

Code: [Select]

Dim CLayer As String

Private Sub AcadDocument_Activate()
 CLayer = ""
End Sub

Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
 Dim DLay As AcadLayer
 If CLayer <> "" Then
  ThisDrawing.SetVariable "CLAYER", CLayer
  CLayer = ""
 End If
 If (CommandName = "XREF") Then
  CLayer = ThisDrawing.GetVariable("CLAYER")
  Set DLay = ThisDrawing.Layers.Add("XREF")
  DLay.Color = acCyan
  ThisDrawing.SetVariable "CLAYER", "XREF"
 End If
End Sub

Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
 On Error GoTo EOS
 If CLayer <> "" Then
  ThisDrawing.SetVariable "CLAYER", CLayer
  CLayer = ""
 End If
EOS:
End Sub


Keith...

This is very nice...

But something missing...

If i use the XREF command and decided to cancel before complete the command...the layer stay at XREF...
After that....if i draw a cercle or a line...the layer return to the previous


also I've modified the code....(suggested by ronjonp)


Code: [Select]
Dim CLayer As String

Private Sub AcadDocument_Activate()
 CLayer = ""
End Sub

Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
 Dim DLay As AcadLayer
 If CLayer <> "" Then
  ThisDrawing.SetVariable "CLAYER", CLayer
  CLayer = ""
 End If
 If (CommandName = "DIM") Then
  CLayer = ThisDrawing.GetVariable("CLAYER")
  Set DLay = ThisDrawing.Layers.Add("ddd")
  DLay.color = acMagenta
  ThisDrawing.SetVariable "CLAYER", "ddd"
 End If
End Sub


Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
 On Error GoTo EOS
 If CLayer <> "" Then
  ThisDrawing.SetVariable "CLAYER", CLayer
  CLayer = ""
 End If
EOS:
End Sub

 but this will not return at the previous layer..;-(

also I have noted that the

 (CommandName = "DIM")

must be in UPPERCASE...otherwise..not working.

another thing is....
I have made tests with the "ddd" layer....
but how can i run the program with a variable set in LISP..

ex:

(setq layer1 "ddd")

can i replace the lines with

  Set DLay = ThisDrawing.Layers.Add(layer1)
  DLay.color = acMagenta
  ThisDrawing.SetVariable "CLAYER", (layer1)

?????????? :?
Keep smile...

ronjonp

  • Needs a day job
  • Posts: 7529
make layer when xref command is executed
« Reply #8 on: February 27, 2005, 07:19:22 PM »
Andrea,

You also might want to add:

Code: [Select]
If dlay.LayerOn = False Then
  dlay.LayerOn = True
 End If
 If dlay.Freeze = True Then
  dlay.Freeze = False
 End If


Just in case the layer is frozen or off that you want to be current.

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Andrea

  • Water Moccasin
  • Posts: 2372
make layer when xref command is executed
« Reply #9 on: February 28, 2005, 09:07:05 AM »
Quote from: ronjonp
Andrea,

You also might want to add:

Code: [Select]
If dlay.LayerOn = False Then
  dlay.LayerOn = True
 End If
 If dlay.Freeze = True Then
  dlay.Freeze = False
 End If


Just in case the layer is frozen or off that you want to be current.

Ron


Oh !  I see..

Thanks ronjonp..this was added... :wink:
but i've got an error message....



Code: [Select]

Dim CLayer As String

Private Sub AcadDocument_Activate()
 CLayer = ""
End Sub

Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
 Dim DLay As AcadLayer
 If CLayer <> "" Then
  ThisDrawing.SetVariable "CLAYER", CLayer
  CLayer = ""
 End If
 If (CommandName = "DIM") Then
  CLayer = ThisDrawing.GetVariable("CLAYER")
  Set DLay = ThisDrawing.Layers.Add("ddd")
  DLay.Color = acMagenta
  ThisDrawing.SetVariable "CLAYER", "ddd"
 End If
 
If DLay.LayerOn = False Then
  DLay.LayerOn = True
 End If
 If DLay.Freeze = True Then
  DLay.Freeze = False
 End If

 
End Sub







Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
 On Error GoTo EOS
 If CLayer <> "" Then
  ThisDrawing.SetVariable "CLAYER", CLayer
  CLayer = ""
 End If
EOS:
End Sub


also.... what about the  (layer1) variable ?
any help ?
Keep smile...

sinc

  • Guest
Re: make layer when xref command is executed
« Reply #10 on: February 28, 2005, 05:34:27 PM »
Quote from: ronjonp
How would you guys go about implementing a layer creation proggie that creates a predetermined layer when a certain command is run?

Something related to this that I wish Autocad would do is retain a "template" pointer for each drawing.  Then when any command creates a layer, Autocad would check the template for a layer with the same name.  If one exists, the layer in the template determines the layer properties.

For example, with default setting, breaklines for the current surface go in on a layer named SRF-FLT.  If no SRF-FLT layer currently exists, one is created with color White, linetype "continuous", and lineweight "default".  I would like to be able to setup a layer named SRF-FLT in the template, and then any layer named SRF-FLT will automatically be created with the color, lineweight, linetype, noplot flag, etc., from the SRF-FLT layer in the template.

It's true that drawing templates, the layer translator, and the design center all accomplish this task in various ways, but drawing templates are the only option that is relatively automatic, and that option is rather limited - purging a drawing can negate its effectiveness.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
make layer when xref command is executed
« Reply #11 on: February 28, 2005, 10:58:51 PM »
I thought "that" progy was already created by someone here. I'll look arround for ya if you want, but im perty sure it was done by using a text file or something not a drawing.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org