VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

help with my ADT 'Generate Layers from Layer Key' Code?

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
364 Views, 4 Replies

help with my ADT 'Generate Layers from Layer Key' Code?

The section: 're-set layer key overrides
below produces the error:

Run-time error '-214746259 (80004005)'
Method 'Value' of Object 'IAecLayerOverrideSettings' failed


See VBA code below:

Sub GenerateLayersFromLayerKey()

getAecArchBaseApp
getAecArchDbPref

Dim CurrentLayerKeyStyle As String
CurrentLayerKeyStyle = getLayerStandard

Dim AecDoc As New AecArchBaseDocument
AecDoc.Init ThisDrawing

Dim LayKeyStyle As AecLayerKeyStyle
Set LayKeyStyle = AecDoc.LayerKeyStyles(CurrentLayerKeyStyle)

'save current Layer Key Overrides
Dim SavedOverrideSettings() As Variant

With LayKeyStyle.OverrideSettings
SavedOverrideSettings = Array((Array(.Item("Discipline").Name,
.Item("Discipline").Value)), _
(Array(.Item("Status").Name,
.Item("Status").Value)), _
(Array(.Item("Component").Name,
.Item("Component").Value)), _
(Array(.Item("Description").Name,
.Item("Description").Value)) _
)
End With

'set Layer Standard Wildcards
With LayKeyStyle.OverrideSettings
.Item("Discipline").Value = "?"
.Item("Status").Value = "-?"
.Item("Component").Value = "-????"
.Item("Description").Value = "-*"
End With

ThisDrawing.SendCommand ("LayerKeyOverride ")

'build Layer Generate Filter String
Dim LayerFilter As String
With LayKeyStyle.OverrideSettings

'Discipline Field is required
If .Item("Discipline").Value <> "" Then
LayerFilter = .Item("Discipline").Value
Else
LayerFilter = LayerFilter & "?"
End If

'Status Field is optional
If .Item("Status").Value <> "" Then
LayerFilter = LayerFilter & .Item("Status").Value
Else
LayerFilter = LayerFilter & "*"
End If

'Component Field is required
If .Item("Component").Value <> "" Then
LayerFilter = LayerFilter & .Item("Component").Value
Else
LayerFilter = LayerFilter & "-????"
End If

'Description Field is optional
If .Item("Description").Value <> "" Then
LayerFilter = LayerFilter & .Item("Description").Value
Else
LayerFilter = LayerFilter & "*"
End If

End With

're-set layer key overrides
For Each x In SavedOverrideSettings
LayKeyStyle.OverrideSettings.Item(x(1)).Value = x(2)
Next x

Dim LayerKey As AecLayerKey

For Each LayerKey In LayKeyStyle.Keys

If LayerKey.Index = 86 Then 'special code for the 'Count' item, I think?
GoTo SkipLayerKey
End If

If LayerKey.Layer Like LayerFilter Then
LayKeyStyle.GenerateLayer (LayerKey.Name)
End If

SkipLayerKey:
Next LayerKey

EndSub:

End Sub
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Corey A. Layton wrote:
> The section: 're-set layer key overrides
> below produces the error:
Ok,
problem solved.
Credit to B.Winterscheidt over in the arch-desktop discussion group.

> ThisDrawing.SendCommand ("LayerKeyOverride ")

The line above was the culprit,
with regard to its position in sequence of things.
Wasn't really behaving 'synchronously', as advertised,...

>'re-set layer key overrides
>For Each x In SavedOverrideSettings
> LayKeyStyle.OverrideSettings.Item(x(1)).Value = x(2)
>Next x

...which caused the code above to error.
Moving this piece of code 'further downstream' to execute just before the
End Sub,
did the trick.

I have *no idea* why...
(but I'll take it!)

> End Sub
Message 3 of 5
Anonymous
in reply to: Anonymous

>Wasn't really behaving 'synchronously', as advertised,...
Who advertised it as being synchronous? We usually go out of our way to tell
everyone to stay away from SendCommand if possible, because it is
asyncronous.

--
----
Ed
----
Message 4 of 5
Anonymous
in reply to: Anonymous

Ed Jobe wrote:
> Who advertised it as being synchronous? We usually go out of our way
> to tell everyone to stay away from SendCommand if possible, because
> it is asyncronous.

snipped from the Help file.



"This method is generally synchronous. However, if the command sent with
this method requires any user interaction (such as picking a point on the
screen) then this method will continue as soon as the user input begins. The
command will then continue to be processed asynchronously."



I guess my use of the Layer Key Overrides UI,
constitutes 'user interaction', eh?

I should read these things more closely...
Message 5 of 5
Anonymous
in reply to: Anonymous

Oh, the "help" file. That blurb is a little misleading,
easily misunderstood. Although SendCommand method is processed syncronously,
the processing of whatever is output to the command line is asyncronous.

--
----
Ed
----

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost