Create/Modify Design Views in ipt

Create/Modify Design Views in ipt

mikeb456
Enthusiast Enthusiast
1,472 Views
6 Replies
Message 1 of 7

Create/Modify Design Views in ipt

mikeb456
Enthusiast
Enthusiast

In Inventor 2018 build 171

 

using vba (for now)

I can run this to change a view called "XY Section" in a PART file from a section to a non-section view:

 

ThisDocument.ComponentDefinition.RepresentationsManager.DesignViewRepresentations("XY Section").SetSectionView kNoSectionViewType

 

but I cannot do anything to make a view a half section as per something like ..

 

ThisDocument.ComponentDefinition.RepresentationsManager.DesignViewRepresentations("XY Section").SetSectionView kHalfSectionViewType,ThisDocument.ComponentDefinition.WorkPlanes(2)

 looking at the API help I suspect the designviewrepresentations only (perhaps fully) applies to assemblies... so perhaps I'm using the wrong bit of the API..

 

Any advice gratefully received.

 

Thanks

 

Mike

 

0 Likes
Accepted solutions (2)
1,473 Views
6 Replies
Replies (6)
Message 2 of 7

MechMachineMan
Advisor
Advisor

Using the VBA editor's watch window and click through the tree for whatever items and you can pretty quickly find what properties/methods are/aren't available on specific objects. That or using the API documentation.

 

Oddly enough, using the code below, it looks like the SetSectionView is NOT available on PartDocument objects; only AssemblyDocuments.

 

(the error "Object of type Inventor._DocumentClass cannot be converted to type Inventor._AssemblyDocument")

 

Seems to be a defect to me, or an unexpected access point since the documentation also references "assemblies" often, instead of the generic document.

 

Sub Main()

    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oPCD As PartComponentDefinition
    Set oPCD = oDoc.ComponentDefinition
    
    Set oSecView = oPCD.RepresentationsManager.DesignViewRepresentations.Add("XY Section")
    oSecView.Activate
    Call oSecView.SetSectionView(kHalfSectionView, oPCD.WorkPlanes(2))

End Sub

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

mikeb456
Enthusiast
Enthusiast

Thanks for confirming Justin.

0 Likes
Message 4 of 7

wolfgang_nickl
Advocate
Advocate
Accepted solution

Hello Raul,

 

it works for both Part an Assembly, with the following code you can cut part or assembly on XZ-Plane.

 

Public Sub subHalfsection()
    Dim oRepManager As RepresentationsManager
    Set oRepManager = ThisApplication.ActiveDocument.ComponentDefinition.RepresentationsManager
    
    Dim oRootPoint As point
    Set oRootPoint = ThisApplication.TransientGeometry.CreatePoint(0, 0, 0)

    Dim oNormal As Vector
    Set oNormal = ThisApplication.TransientGeometry.CreateVector(0, -1, 0)

    Dim oPlane As Plane
    Set oPlane = ThisApplication.TransientGeometry.CreatePlane(oRootPoint, oNormal)

    Call oRepManager.ActiveDesignViewRepresentation.SetSectionView(kHalfSectionViewType, oPlane)
End Sub

Best Regards

 

Wolfgang

Message 5 of 7

mikeb456
Enthusiast
Enthusiast

Indeed it does 🙂

 

Thanks

0 Likes
Message 6 of 7

j_weber
Mentor
Mentor

Great, 

absolute fantastic.

It reduce many clicks and is very helpfull

 

Thanks a lot




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





0 Likes
Message 7 of 7

clutsa
Collaborator
Collaborator
Accepted solution

I was trying to do something similar to 


Sub Main()

    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oPCD As PartComponentDefinition
    Set oPCD = oDoc.ComponentDefinition
    
    Set oSecView = oPCD.RepresentationsManager.DesignViewRepresentations.Add("XY Section")
    oSecView.Activate
    Call oSecView.SetSectionView(kHalfSectionView, oPCD.WorkPlanes(2))

End Sub

It looks like SetSectionView wants a plane "Plane" not a "WorkPlane"

Sub Main()
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oPCD As ComponentDefinition
    Set oPCD = oDoc.ComponentDefinition
    
    Set oSecView = oPCD.RepresentationsManager.DesignViewRepresentations.Add("XY Section")
    oSecView.Activate
    Call oSecView.SetSectionView(SectionViewTypeEnum.kHalfSectionViewType, oPCD.WorkPlanes(2).Plane)

End Sub

Anyway I know this was answered but maybe this will help someone else down the road.

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates