TheSwamp
Code Red => VB(A) => Topic started by: Guest 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.
-
Matt -
You can use something along these lines:
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
-
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).
-
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
-
This worked for me in 2007, but, as Bryco points out, there is no Intellisense using this method.
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
-
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).
-
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
-
Thanks for the help/info everyone!
-
It works on 2006 for me, did you try it Dave?
-
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?
-
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!