Component Invisibility in Drawing Macro Trouble

Component Invisibility in Drawing Macro Trouble

Anonymous
Not applicable
499 Views
5 Replies
Message 1 of 6

Component Invisibility in Drawing Macro Trouble

Anonymous
Not applicable
All,
I am working on a macro to try and make certain components invisible in a drawing view and am having a hangup with the code I am posting below. As I test the code I find that I can cause components to be suppressed, but cannot change their visibility. I have had success with this basic code on assemblies, but am having some trouble with the drawing files.

Can someone please point me in the right direction? Thanks and have a great day!

Public Sub Inventor_Automatic_Component_Invisibility()

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
Set oSheet = oDoc.ActiveSheet

Dim oAssyDoc As AssemblyDocument
Set oAssyDoc = oSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument

Dim oCompDef As Inventor.ComponentDefinition
Set oCompDef = oAssyDoc.ComponentDefinition

Dim oComponent As ComponentOccurrence

For Each oComponent In oCompDef.Occurrences
Select Case oComponent.Name
Case "Part1"
oComponent.Suppress
Case "Part2"
oComponent.Visible = False
Case "Part3"
oComponent.Suppress
End Select
Next

End Sub
0 Likes
500 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
You have to set the visibility using the DrawingView like so:

DrawingView.SetVisibiliy(oComponent, true)'or false

You might have to assign the DrawingView to a variable first, I
haven't actually tried this, but I was looking for something in the
past where I could do both visibility and turn on/off hidden line
mode on an occurence. I gave up when I found out that the API still
doesn't support the hidden line option. Should work for visiblity
though. You can lookup the DrawingView.SetVisibilty method in the
API docs.

Bob S.

On 2010/06/01 2:38 PM, puertoricanpete wrote:
> All,
> I am working on a macro to try and make certain components invisible in a drawing view and am having a hangup with the code I am posting below. As I test the code I find that I can cause components to be suppressed, but cannot change their visibility. I have had success with this basic code on assemblies, but am having some trouble with the drawing files.
>
> Can someone please point me in the right direction? Thanks and have a great day!
>
> Public Sub Inventor_Automatic_Component_Invisibility()
>
> Dim oDoc As DrawingDocument
> Set oDoc = ThisApplication.ActiveDocument
>
> Dim oSheet As Sheet
> Set oSheet = oDoc.ActiveSheet
>
> Dim oAssyDoc As AssemblyDocument
> Set oAssyDoc = oSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
>
> Dim oCompDef As Inventor.ComponentDefinition
> Set oCompDef = oAssyDoc.ComponentDefinition
>
> Dim oComponent As ComponentOccurrence
>
> For Each oComponent In oCompDef.Occurrences
> Select Case oComponent.Name
> Case "Part1"
> oComponent.Suppress
> Case "Part2"
> oComponent.Visible = False
> Case "Part3"
> oComponent.Suppress
> End Select
> Next
>
> End Sub
0 Likes
Message 3 of 6

Anonymous
Not applicable
Bob, I guess I am having some trouble with this. Could you please put in a line of code to make sure I am using your suggestion correctly? I would really appreciate it. Thanks for the tip and I'll keep plugging away.
0 Likes
Message 4 of 6

Anonymous
Not applicable
I have posted the modified code below, after taking into account Bob's suggestion. However, I am not getting a run time error '-2147467259 (80004005)', that states:

"Method 'SetVisibility' of object 'DrawingView' failed

Can anyone dissect what I have done and offer some advice or better application of the principal?



Public Sub Inventor_Automatic_Component_Invisibility()

Dim oDoc As Inventor.DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
Set oSheet = oDoc.ActiveSheet

Dim oViewDef As DrawingView
Set oViewDef = oSheet.DrawingViews(1)

Dim oAssyDoc As AssemblyDocument
Set oAssyDoc = oSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument

Dim oCompDef As Inventor.ComponentDefinition
Set oCompDef = oAssyDoc.ComponentDefinition

Dim oComponent As ComponentOccurrence

For Each oComponent In oCompDef.Occurrences
Select Case oComponent.Name
Case "Part1"
oViewDef.SetVisibility oComponent, False
End Select
Next

End Sub
0 Likes
Message 5 of 6

YuhanZhang
Autodesk
Autodesk
The failure occurs when you are trying to suppress the last visible component. You can add an Error handler(like On Error Resume Next) to go pass this failure.


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 6 of 6

Anonymous
Not applicable
Thanks for the help. That fixed up the trouble. In fact, thanks to everyone, as the macro is working great!
0 Likes