To switch view representations in te assembly (also need for LOD)

To switch view representations in te assembly (also need for LOD)

RoyWickrama_RWEI
Advisor Advisor
694 Views
6 Replies
Message 1 of 7

To switch view representations in te assembly (also need for LOD)

RoyWickrama_RWEI
Advisor
Advisor

I am on the process of creating the assembly for a re-tractable belt feeder. One of functionality I need is to use an iLogic to switch view representations.

 

'PART 1: for Assembly view representations

'define current document

Dim openDoc As Document

openDoc = ThisDoc.Document

Dim oAsmCompDef As AssemblyComponentDefinition

'oAsmCompDef = openDoc.ComponentDefinition

oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oViewRep As DesignViewRepresentation

Dim oOccurrence As ComponentOccurrence

oViewRep = "Default"

oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("oViewRep").activate

 

'PART 2: for View representations in the sub-assemblies

'Iterate through all Of the occurrences

For Each oOccurrence In oAsmCompDef.Occurrences

oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("oViewRep").activate

Next

 

I spent a lot of time including got some help from Web. The idea was running once. Later I started to make it better (timmed down) - suddenly, everything messed up. Even, I lost the iLogic that I had doing well.

 

Main assembly and sub assemblies all have:

Default

Sketches_On

For_Constraining

view representations mostly. I need to switch as I need them.

 

Request providing code for achieving the similar results forLODs too. Will seek help if necessary.

Note: This is one of my home projects. I aim at getting iLogic skills by working from home after work. At work, I don.t use iLogic at all.

 

Autodesk Inventor 2015

Vault Basic 2015

 

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

RoyWickrama_RWEI
Advisor
Advisor
Accepted solution

I got the solution today by myself (also thanks for the postings in general). Please see the attached. I still look forward to receiving feedback. Thanks. '----------------------Part 1: To Restore "Default" view representation------------ ThisApplication.CommandManager.ControlDefinitions.Item ("AppViewCubeHomeCmd").Execute 'define current document Dim openDoc As Document openDoc = ThisDoc.Document Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = openDoc.ComponentDefinition Dim oViewRep As DesignViewRepresentation ThisApplication.CommandManager.ControlDefinitions.Item ("AppViewCubeHomeCmd").Execute Try 'Activate a writeable View Rep (master view rep is not writeable) oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("WIP_View_Rep").activate Catch 'Assume error means this View Rep does not exist, so create it (will be deleted at end) oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("WIP_View_Rep") End Try 'Delete all existing 'Contains' View reps For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations If oViewRep.Name.Contains("Default") Then oViewRep.activate End If Next Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition 'define the first level components collection Dim oCompOcc As Inventor.ComponentOccurrence 'define the next level components collection Dim oSubCompOcc As Inventor.ComponentOccurrence 'Turn off the visibility of parts in the top level assembly that don't contain the specified text string (StrInput1) For Each oCompOcc in oCompDef.Occurrences ' If oCompOcc.Suppressed = False Then 'eg: Suppressed 'If oCompOcc.Name.Contains(StrInput1) Then oCompOcc.Visible = True 'Increment counter for top level components oCompOcc.SetDesignViewRepresentation("Default",, True) Else oCompOcc.Visible = False End If Next 'Zoom all ThisApplication.ActiveView.Fit '------------------Part 2: To create view representations for sub-assemblies in the main model------------------------- ThisApplication.CommandManager.ControlDefinitions.Item ("AppViewCubeHomeCmd").Execute 'define current document Dim openDoc As Document openDoc = ThisDoc.Document Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = openDoc.ComponentDefinition Dim oViewRep As DesignViewRepresentation ThisApplication.CommandManager.ControlDefinitions.Item ("AppViewCubeHomeCmd").Execute Try 'Activate a writeable View Rep (master view rep is not writeable) oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("WIP_View_Rep").activate Catch 'Assume error means this View Rep does not exist, so create it (will be deleted at end) oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("WIP_View_Rep") End Try '[ ''Delete all existing 'Contains' View reps 'For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations ' If oViewRep.Name.Contains("Contains") Then ' oViewRep.Delete ' End If 'Next '] Start: 'request part names to create view reps for. N_Loop = 50 Do Until iCount = N_Loop StrInput1 = InputBox("Enter Part Names to Add to View Rep", "Set View Representations", "Enter all or part of PN",MessageBoxDefaultButton.Button1) 'Check to see whether that view rep has already been created ViewRepExists = 0 For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations 'MessageBox.Show("Message 1-1: " & oViewRep.Name, "Title") If oViewRep.Name.Contains("Contains" & " " & StrInput1) Then 'If oViewRep.Name.Contains("Contains" & " " & StrInput1 & "'") Then ViewRepExists = 1 oCreatedAlready = MessageBox.Show("That View Rep Already Created!" & vbLf _ & vbLf & "" _ & vbLf & "Do You Still Want To Continue?","VIEW REP AVAILABLE!",MessageBoxButtons.YesNo) If oCreatedAlready = vbYes Then Goto Start Else Return End If End If Next If ViewRepExists = 0 Then 'Create new View Rep 'MessageBox.Show("New View Rep Name: " & oViewRep.Name, "Title") oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("Contains" & " " & StrInput1) 'Activate new View Rep oViewRep.activate MessageBox.Show("New View Rep Name (2): " & oViewRep.Name, "Title") End If 'look at all of the components in the assembly Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition 'define the first level components collection Dim oCompOcc As Inventor.ComponentOccurrence 'define the next level components collection Dim oSubCompOcc As Inventor.ComponentOccurrence 'Turn off the visibility of parts in the top level assembly that don't contain the specified text string (StrInput1) For Each oCompOcc in oCompDef.Occurrences If oCompOcc.Suppressed = False Then 'eg: Suppressed If oCompOcc.Name.Contains(StrInput1) Then oCompOcc.Visible = True 'Increment counter for top level components oCompOcc.SetDesignViewRepresentation("Default",, True) Else oCompOcc.Visible = False End If ' If oCompOcc.Name.Contains("0011") Then ' oCompOcc.Visible = True ' 'Increment counter for top level components ' oCompOcc.SetDesignViewRepresentation("Default",, True) ' MessageBox.Show("Check: ", "Title") ' End If End If Next 'Rename View Rep to include component counts oViewRep.Name = ("DVR: " & StrInput1) 'lock the new view rep oViewRep.Locked = False 'oViewRep.Locked = True '[ ' 'Count no. of view reps already created ' ViewRepCount = 0 ' For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations ' If oViewRep.Name.Contains("Contains") Then ' ViewRepCount = ViewRepCount + 1 ' End If ' Next '] 'Zoom all ThisApplication.ActiveView.Fit 'See if another View Rep is required. oContinue = MessageBox.Show("LAST - Add Another View Rep?" & vbLf & ViewRepCount & " View Reps Have Been Created", "Continue Creating?",MessageBoxButtons.YesNo) If oContinue = vbYes Then iCount = iCount+1 If oContinue = vbNo Then iCount = N_Loop Loop Try 'Delete WIP View Rep oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("WIP_View_Rep").delete Catch End Try ThisApplication.CommandManager.ControlDefinitions.Item ("AppViewCubeHomeCmd").Execute

0 Likes
Message 3 of 7

RoyWickrama_RWEI
Advisor
Advisor

My posting (reply) is too wordy. My cut and paste did not work well. I did not expect this. How culd I do this properly?

0 Likes
Message 4 of 7

adam.nagy
Autodesk Support
Autodesk Support

Just click the insert code button 🙂

InsertCode.png

Then the code will look like this, e.g.

Documents.CloseAll( [UnreferencedOnly] As Boolean )


Adam Nagy
Autodesk Platform Services
Message 5 of 7

RoyWickrama_RWEI
Advisor
Advisor
'Upper Limit and Lower Limit of Model Parameters


Dim oDoc as Inventor.PartDocument = ThisDoc.Document
Dim oParameters as Inventor.Parameters = oDoc.ComponentDefinition.Parameters
Dim oLengthParam As Parameter
oParameters.SetAllToMedian()


Parameter.Param("Length_1").Tolerance.SetToDeviation(".2 mm" , "-.2 mm")  'will set tolerace

' First part - Read the parameter tolerance

Above is just for sample. Thanks a lot. 

0 Likes
Message 6 of 7

RoyWickrama_RWEI
Advisor
Advisor
Hi Adam;
I am eager to create some modelling (large assembly) which are a kind of advanced in nature and complete with each and every drawing. The first in this is a belt feeder. I posted for help to get around the view representations for the parts and sub-assemblies. I request you try to help me. Thanks.
0 Likes
Message 7 of 7

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

You already marked your answer as a solution. What changed since then? What exact issue did you run into?

 

Coud you try to narrow down the issue on your side so that it's reproducible with a minimal set of non-confidential files and then provide the exact steps we need to follow and point out what you'd like to happen and what happens instead?

 

Cheers, 



Adam Nagy
Autodesk Platform Services
0 Likes