Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Component Invisibility in Drawing Macro Trouble

5 REPLIES 5
Reply
Message 1 of 6
puertoricanpete
393 Views, 5 Replies

Component Invisibility in Drawing Macro Trouble

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
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: puertoricanpete

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
Message 3 of 6

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.
Message 4 of 6

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
Message 5 of 6

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.

Message 6 of 6

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

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

Post to forums  

Autodesk Design & Make Report