TheSwamp

Code Red => VB(A) => Topic started by: hardwired on November 12, 2009, 03:01:53 AM

Title: VBA or Diesel expressions for layers on?
Post by: hardwired on November 12, 2009, 03:01:53 AM
Hi,

Could someone help me out with a diesel expression (and VBA) i can use for a button macro? I want to toggle a layer on or off, nothing more than that but i don't know much diesel..

The layer is LSC-WATERMARK, so its only gonna be like:
If LSC-WATERMARK is ON then, turn OFF LSC-WATERMARK and vice versa (obvious i know)..

I've posted this in the AutoLISP forum to request the AutoLISP and Diesel versions..

Thanks in advance,
Title: Re: VBA or Diesel expressions for layers on?
Post by: ChristopherF on November 18, 2009, 03:36:06 PM
Hi,

Could someone help me out with a diesel expression (and VBA) i can use for a button macro? I want to toggle a layer on or off, nothing more than that but i don't know much diesel..

The layer is LSC-WATERMARK, so its only gonna be like:
If LSC-WATERMARK is ON then, turn OFF LSC-WATERMARK and vice versa (obvious i know)..

I've posted this in the AutoLISP forum to request the AutoLISP and Diesel versions..

Thanks in advance,

Here's how to do it VBA:

Sub TurnOffLayer()

    If ThisDrawing.Layers.Item("LSC-WATERMARK").LayerOn = True Then
        ThisDrawing.Layers.Item("LSC-WATERMARK").LayerOn = False
    Else
        ThisDrawing.Layers.Item("LSC-WATERMARK").LayerOn = True
    End If
   
End Sub
Title: Re: VBA or Diesel expressions for layers on?
Post by: Keith™ on November 18, 2009, 05:00:10 PM
I don't see the LISP entry, so here it is in lisp ...

Code: [Select]
(if (< -1 (cdr(assoc 62 (tblsearch "layer" "LSC-WATERMARK"))))
  (vl-cmdf "-layer" "off" "LSC-WATERMARK" "")
  (vl-cmdf "-layer" "on" "LSC-WATERMARK" "")
)
Title: Re: VBA or Diesel expressions for layers on?
Post by: Bobby C. Jones on November 20, 2009, 04:45:31 PM
Here's how to do it VBA:

Sub TurnOffLayer()

    If ThisDrawing.Layers.Item("LSC-WATERMARK").LayerOn = True Then
        ThisDrawing.Layers.Item("LSC-WATERMARK").LayerOn = False
    Else
        ThisDrawing.Layers.Item("LSC-WATERMARK").LayerOn = True
    End If
   
End Sub

Another concise way to toggle a bool value is to simply set the value to what it's Not.
Title: Re: VBA or Diesel expressions for layers on?
Post by: ChristopherF on November 20, 2009, 07:34:17 PM
Another concise way to toggle a bool value is to simply set the value to what it's Not.

Thanks, learned something new today. It is way more consice.

ThisDrawing.Layers.Item("LSC-WATERMARK").LayerOn = Not ThisDrawing.Layers.Item("LSC-WATERMARK").LayerOn