VBA Suppress / Unsuppress drawing view

VBA Suppress / Unsuppress drawing view

Jacques.Grobler
Advocate Advocate
1,379 Views
10 Replies
Message 1 of 11

VBA Suppress / Unsuppress drawing view

Jacques.Grobler
Advocate
Advocate
Hi all

I have a drawing that has to suppress / unsuppress a view as the model changes. How can I do this with VBA?
0 Likes
Accepted solutions (1)
1,380 Views
10 Replies
Replies (10)
Message 2 of 11

mwighton
Collaborator
Collaborator
You can write a rule that will supress/unsuppress the view using If_Else statements.
Did this post help out? Hope it did.
If so please use the 'Accept as Solution' or 'Kudos' Button below.
God Bless

Mwighton
0 Likes
Message 3 of 11

Jacques.Grobler
Advocate
Advocate
Hi mwighton

That is what I am trying to do in VBA however I have no idea of where to start
0 Likes
Message 4 of 11

mwighton
Collaborator
Collaborator
The way I would do it, is...

Create a parameter in your model that will change based on when you want the view to be present or not.

Link that parameter to your drawing.

Create the rule that will suppress/unsuppress the view.

If you can attach the model and drawing file so I can take a look I would be happy to help. Also tell me which view is the one that would be suppressed and when.
Did this post help out? Hope it did.
If so please use the 'Accept as Solution' or 'Kudos' Button below.
God Bless

Mwighton
0 Likes
Message 5 of 11

Jacques.Grobler
Advocate
Advocate
All I am looking for is the piece of code that says:

If modelstate = true then
Drawing.view (5).visible = true 'help with this line pls
Else
Drawing.view (5).visible = false
End if
0 Likes
Message 6 of 11

mwighton
Collaborator
Collaborator

You can try reading This.

Did this post help out? Hope it did.
If so please use the 'Accept as Solution' or 'Kudos' Button below.
God Bless

Mwighton
0 Likes
Message 7 of 11

Jacques.Grobler
Advocate
Advocate
This is for rules in iLogic, I specifically need it for VBA pls
0 Likes
Message 8 of 11

MechMachineMan
Advisor
Advisor

From the link posted above:

 

{code}
Sub Main() 
FindView("VIEW2").Suppressed = True
End Sub

Function FindView(viewName As String) as DrawingView
Dim doc As DrawingDocument = ThisDoc.Document
For Each view as DrawingView in doc.ActiveSheet.DrawingViews
If (view.Name = viewName) Then
Return view
End If
Next
Throw New ArgumentException(" No view named " & viewName & " was found") 
End Function
{code}

 

Use the basics from that with this:

api HELP.JPG 

and you have a working program! Yay!

 

DrawingView.Suppressed Property DrawingView.Suppressed() As Boolean


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 9 of 11

Jacques.Grobler
Advocate
Advocate

Hi Guys

 

I am still not getting this code to work. Can someone please assist me?

0 Likes
Message 10 of 11

MechMachineMan
Advisor
Advisor
Where you stuck at? And this is almost definitely gonna take learning on your part to figure out which Feature will cause the view suppression to occur, unless you just have a manual parameter or something...

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 11 of 11

Jacques.Grobler
Advocate
Advocate
Accepted solution

And after a bit of a struggle< I finally got the code right

 

Thanks for all the help guys

 

Sub viewDrawing_Toggle(viewName As String, boolStatus)
   
    Dim drgDoc As DrawingDocument
    Set drgDoc = ThisApplication.ActiveDocument

    Dim drg As DrawingViews
    Set drg = drgDoc.ActiveSheet.DrawingViews

    Dim drgView As DrawingView
    Set drgView = drg(viewName)

    drgView.Suppressed = Not boolStatus

End Sub
0 Likes