Hide non Sheetmetal parts in assembly and sub-assembly

Hide non Sheetmetal parts in assembly and sub-assembly

jason-dave.baker
Contributor Contributor
543 Views
7 Replies
Message 1 of 8

Hide non Sheetmetal parts in assembly and sub-assembly

jason-dave.baker
Contributor
Contributor
'Valide si le document ouvert est un assemblage ou non, si non, demande d'ouvrir un assemblage pour rouler la macro (12290 = .ipt, 12291 = .iam , 12292 = .idw)
Dim oDocType = ThisApplication.ActiveDocument.DocumentType
If oDocType = 12291 Then
Else 
	MsgBox("Ouvrir un assemblage pour rouler la macro") 
End If

'Création vue SheetMetalOnly
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition

Dim oViewRep As DesignViewRepresentation
Try
oAsmDef.RepresentationsManager.DesignViewRepresentations.Item("SheetMetalOnly").Activate
Catch
 oViewRep = oAsmDef.RepresentationsManager.DesignViewRepresentations.Add("SheetMetalOnly")
 'Activate new View Rep
 oviewrep.activate
End Try

' Reading Child part(leaf occurrences) of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator = oAsmDef.Occurrences.AllLeafOccurrences
Dim oOcc As ComponentOccurrence


' Iterate through all part occurrences in assembly.

For Each oOcc In oLeafOccs

Dim oOccCrntStyle = SheetMetal.GetActiveStyle() MsgBox(oOccCrntStyle) If oCompOccCrntStyle Is Nothing Then kPartsListObject.visible = False Else 'kPartsListObject.Visible = True End If
Next

 I am trying to get an iLogic to scan through an assembly and hide all the parts that are not Sheetmetal.

Here is what I have so far.
It looks if the file is an assembly or part and Tells to open one before you close the window and then crashes if it's a part that is opened
Then it creates a "SheetMetalOnly" View rep
Next scans the assembly and get all of the part occurences in the assembly and subassemblies,
but I can't find how to look on each occurence if it is a sheet metal part or a standard part.

The message box shows that it does not get any information from the Sheetmetal.getactivestyle.

 

Am I on the right track or using the right function? 

Is it possible to get the selected occurence to activate itself and get its information once activated?

 

Thanks!

0 Likes
Accepted solutions (2)
544 Views
7 Replies
Replies (7)
Message 2 of 8

NSBowser
Advocate
Advocate
Accepted solution

You can tell if a document is sheet metal or not by checking its subtype (see below)

Here is a link to an example from the API Help 

 

If oOcc.Definition.Document.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" = True Then ...

 


Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
Message 3 of 8

jason-dave.baker
Contributor
Contributor

Thank you! That's exactly what was missing.

Message 4 of 8

jason-dave.baker
Contributor
Contributor

Is there a way to get the iproperties of the occurences?

0 Likes
Message 5 of 8

NSBowser
Advocate
Advocate

Occurrences are instances of documents. Like before when we wanted to know the document sub-type, we must access the document-wide data from the document.  Be aware the new instance properties operate differently.

 

I would suggest you look into this.

A quick google search can provide a lot of information!


Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
Message 6 of 8

jason-dave.baker
Contributor
Contributor
Accepted solution

Here is the final iLogic that will be used:

 

 

'Validate if the opened document is an assembly, if not, Asks to open one to run the iLogic before Crashing (12290 = .ipt, 12291 = .iam , 12292 = .idw)
Dim oDocType = ThisApplication.ActiveDocument.DocumentType
If oDocType = 12291 Then
Else 
	MsgBox("Open an assembly to run the macro") 
End If

'SheetMetalOnly view rep creation
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim oViewRep As DesignViewRepresentation

Try
oAsmDef.RepresentationsManager.DesignViewRepresentations.Item("SheetMetalOnly").Activate
Catch
oViewRep = oAsmDef.RepresentationsManager.DesignViewRepresentations.Add("SheetMetalOnly")
'Activate new View Rep
oviewrep.activate
End Try

' Reading Child part(leaf occurrences) of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator = oAsmDef.Occurrences.AllLeafOccurrences
Dim oOcc As ComponentOccurrence

For Each oOcc In oLeafOccs
	 'CHecks if Occurence is Sheet metal and if not, turns its visibility off	 
	If oOcc.Definition.Document.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" = False Then
	oOcc.Visible = False
	Else
	End If
	 'CHecks if Occurence is a Purchased part and if so, turns its visibility off
	If oOcc.Definition.BOMStructure = "51973" = True Then
	oOcc.Visible = False
	Else
	End If
		 
Next

 

0 Likes
Message 7 of 8

NSBowser
Advocate
Advocate

Did you decide you did not need to access the iProperties after all? It looks like maybe you used the 'Purchased' part designation instead? Let us know if you didn't get that part working as desired, specifically which iProperty you were trying to access.


Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
0 Likes
Message 8 of 8

jason-dave.baker
Contributor
Contributor

I wanted to use Partnumber or Stocknumber but discovered that it would not solve my problem, so decided to go with the Purchased option instead.

 

Thanks for your help and thanks for link to the levels explanations. This will help for sure for futur iLogics!

0 Likes