Copy View Rep to LOD with iLogic

Copy View Rep to LOD with iLogic

s.pollard
Participant Participant
258 Views
2 Replies
Message 1 of 3

Copy View Rep to LOD with iLogic

s.pollard
Participant
Participant

Hi all,

I originally successfully created a LOD via iLogic but realized that by doing so with

Component.IsActive(oOcc.Name) = False 

The BOM structure for all of the suppressed parts becomes Reference, which is not what I want.

I've since decided to try to create a View Rep and copy to LOD which should have no effect on the BOM structure.

I can create the View rep but cannot work out or find any code that will copy to LOD. Can anyone assist me please?

(I've left the original lines of code in as shown below incase there may be an easy tweak to my original attempt)

Dim oDoc As Document = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

'Try
'oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("fasteners removed").Activate 
'Catch
'oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("fasteners removed")
'End Try

Try
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("fasteners removed").Activate 
Catch
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("fasteners removed")
End Try

Dim oOcc As ComponentOccurrence
'loop through every part
'For Each oOcc In ThisDoc.Document.ComponentDefinition.Occurrences'.AllLeafOccurrences
	
'	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 4) = "SHCS" Then Component.IsActive(oOcc.Name) = False
'	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 15) = "HEX REGULAR NUT" Then Component.IsActive(oOcc.Name) = False
'	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 12) = "HEX HIGH NUT" Then Component.IsActive(oOcc.Name) = False
'	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 12) = "HEX THIN NUT" Then Component.IsActive(oOcc.Name) = False
'	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 14) = "PREVAILING HEX" Then Component.IsActive(oOcc.Name) = False
'	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 14) = "HEX HEAD SCREW" Then Component.IsActive(oOcc.Name) = False
'	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 13) = "HEX HEAD BOLT" Then Component.IsActive(oOcc.Name) = False
'	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 22) = "HEX SOCKET COUNTERSUNK" Then Component.IsActive(oOcc.Name) = False
'	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 6) = "WASHER" Then Component.IsActive(oOcc.Name) = False
	
'Next

For Each oOcc In ThisDoc.Document.ComponentDefinition.Occurrences'.AllLeafOccurrences
	
	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 4) = "SHCS" Then Component.Visible(oOcc.Name) = False
	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 15) = "HEX REGULAR NUT" Then Component.Visible(oOcc.Name) = False
	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 12) = "HEX HIGH NUT" Then Component.Visible(oOcc.Name) = False
	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 12) = "HEX THIN NUT" Then Component.Visible(oOcc.Name) = False
	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 14) = "PREVAILING HEX" Then Component.Visible(oOcc.Name) = False
	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 14) = "HEX HEAD SCREW" Then Component.Visible(oOcc.Name) = False
	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 13) = "HEX HEAD BOLT" Then Component.Visible(oOcc.Name) = False
	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 22) = "HEX SOCKET COUNTERSUNK" Then Component.Visible(oOcc.Name) = False
	If Left(iProperties.Value(oOcc.Name, "Project", "Description"), 6) = "WASHER" Then Component.Visible(oOcc.Name) = False
	
Next

ThisDoc.Save


oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Master").Activate 

It's probably obvious I'm no coder, just chopping and changing to suit. 

Any help would much appreciated.

0 Likes
Accepted solutions (1)
259 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @s.pollard.  I assume that since you are using the LOD (LevelOfDetailRepresentation) term, you must be using a 2021 or older version of Inventor, right?  If so, then the name of the method of the DVR (DesignViewRepresentation) I have in mind for this task was CopyToLevelOfDetail.  If using 2022 or later version, the equivalent method is CopyComponentVisibilityToSuppression.  Once you have a DVR the way you want it, you can use that method of that DVR to create an LOD (or ModelState) in which all the components that are not visible are suppressed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

s.pollard
Participant
Participant

Thanks @WCrihfield for the reply and you're right we're using 2021. I tinkered a little and discovered it was as simple as changing the 

Component.IsActive(oOcc.Name) = False

to, oOcc.Suppress. 

This seems to have no effect on the BOM status but achieves the same result. From there I create the View Rep using the same method as previous, so all works fine.

Thanks again as I'll refer back to this when we upgrade to 2022 or later.

0 Likes