Author Topic: Dynamic Block Vis State  (Read 4209 times)

0 Members and 1 Guest are viewing this topic.

Guest

  • Guest
Dynamic Block Vis State
« on: December 04, 2006, 10:22:57 AM »
Is it possible to change the visibility state of a dynamic block using VBA??  I can't seem to find any properties for visibility states.

Thanks.

Dave R

  • Guest
Re: Dynamic Block Vis State
« Reply #1 on: December 04, 2006, 12:35:24 PM »
Matt -

You can use something along these lines:

Code: [Select]
Sub SetDynBlockToElevation()

  Dim ent As AcadEntity
  Dim oSSet As AcadSelectionSet
  Dim oBlkRef As IAcadBlockReference2
  Dim vDynProps As Variant
  Dim oDynProp As AcadDynamicBlockReferenceProperty
  Dim iCnt As Long
 
  Set oSSet = vbdPowerSet("DynBlock")
  oSSet.Select acSelectionSetLast
   
  Set oBlkRef = oSSet.Item(0)
  vDynProps = oBlkRef.GetDynamicBlockProperties
  For iCnt = LBound(vDynProps) To UBound(vDynProps)
    Set oDynProp = vDynProps(iCnt)
    If oDynProp.PropertyName = "Visibility" Then
      If oDynProp.Value = "Plan" Then
         oDynProp.Value = "Elevation"
      End If
    End If
  Next iCnt
End Sub

Public Function vbdPowerSet(strName As String) As AcadSelectionSet
  Dim objSelSet As AcadSelectionSet
  Dim objSelCol As AcadSelectionSets
  Set objSelCol = ThisDrawing.SelectionSets
    For Each objSelSet In objSelCol
      If objSelSet.Name = strName Then
        objSelCol.Item(strName).Delete
        Exit For
      End If
    Next
  Set objSelSet = objSelCol.Add(strName)
  Set vbdPowerSet = objSelSet
End Function

Guest

  • Guest
Re: Dynamic Block Vis State
« Reply #2 on: December 04, 2006, 01:32:13 PM »
Thanks, but.....

It throws a wobbly right here: Dim oBlkRef As IAcadBlockReference2
Did you have to add any references to anything??  I'm using 2007 (for what it's worth).


Bryco

  • Water Moccasin
  • Posts: 1883
Re: Dynamic Block Vis State
« Reply #3 on: December 04, 2006, 05:21:44 PM »
As far as I can tell you Dim oBlkRef As IAcadBlockReference2 to get intellisense but after that you can change it to Dim oBlkRef As AcadBlockReference

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Dynamic Block Vis State
« Reply #4 on: December 04, 2006, 06:27:20 PM »
This worked for me in 2007, but, as Bryco points out, there is no Intellisense using this method.

Code: [Select]
Sub test()
Dim oBlkRef As AcadBlockReference
Dim oEnt As AcadEntity
Dim vPick As Variant
Dim vDynProps As Variant
Dim oDynProp As AcadDynamicBlockReferenceProperty
Dim i As Long

ThisDrawing.Utility.GetEntity oEnt, vPick, "select block: "
If TypeOf oEnt Is AcadBlockReference Then
    Set oBlkRef = oEnt
    If oBlkRef.IsDynamicBlock = True Then
        vDynProps = oBlkRef.GetDynamicBlockProperties
        For i = 0 To UBound(vDynProps)
            Set oDynProp = vDynProps(i)
            If oDynProp.PropertyName = "Visibility" Then
                Debug.Print oDynProp.Value
            End If
        Next
    End If
End If

End Sub

Dave R

  • Guest
Re: Dynamic Block Vis State
« Reply #5 on: December 05, 2006, 07:54:04 AM »
Matt -

I'm using 2006. 2007 may be a little different.

Thanks, but.....

It throws a wobbly right here: Dim oBlkRef As IAcadBlockReference2
Did you have to add any references to anything??  I'm using 2007 (for what it's worth).



Dave R

  • Guest
Re: Dynamic Block Vis State
« Reply #6 on: December 05, 2006, 07:55:30 AM »
Bryco -

In AutoCAD 2006 you have to use IAcadBlockReference2 in order to access the GetDynamicBlockProperties method. This may have changed for 2007.

As far as I can tell you Dim oBlkRef As IAcadBlockReference2 to get intellisense but after that you can change it to Dim oBlkRef As AcadBlockReference

Guest

  • Guest
Re: Dynamic Block Vis State
« Reply #7 on: December 05, 2006, 08:53:07 AM »
Thanks for the help/info everyone!

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Dynamic Block Vis State
« Reply #8 on: December 05, 2006, 10:10:45 AM »
It works on 2006 for me, did you try it Dave?

Dave R

  • Guest
Re: Dynamic Block Vis State
« Reply #9 on: December 05, 2006, 01:16:22 PM »
Not yet, but I will.

Matt -
Did you manage to make it work for you?

It works on 2006 for me, did you try it Dave?

Guest

  • Guest
Re: Dynamic Block Vis State
« Reply #10 on: December 05, 2006, 01:29:03 PM »
Quote
Matt -
Did you manage to make it work for you?

So far, so good.  I'm going to take some of Jeff's code, some of your code, mix it together, throw it against the wall and see if it sticks (I think it will).  :)

Thanks again!