help export step file to iam

help export step file to iam

leoa.87
Contributor Contributor
2,866 Views
33 Replies
Message 1 of 34

help export step file to iam

leoa.87
Contributor
Contributor
hello, I need some help ...
i have an assembly file with ilogic rules and part and subassemblies.
according to certain ilogic rules I need to export only the visible elements and not all the parts present in the assembly to file step.
I found a rule already made and it works but not as I would like.

the problem is this rule exports the visible files but also the derivatives which, however, are not visible in the assembly.

how could I do not to make it exhibit a derivative part.

the derived part is used for a mirrored part so in my assembly it is not visually present.

I can't delete the link with the derived part because it's all parametric and I need the parameters

the rule I am using is this:

Sub Main()
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)

'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If

'get user input
' If MessageBox.Show ( _
' "This will create a STP file for all of the asembly components that have drawings files." _
' & vbLf & "This rule expects that the drawing file shares the same name and location as the component." _
' & vbLf & " " _
' & vbLf & "Are you sure you want to create STP Drawings for all of the assembly components?" _
' & vbLf & "This could take a while.", "iLogic - Batch Output STPs ",MessageBoxButtons.YesNo) = vbNo Then
'
' Exit Sub
' End If

Dim STEPTranslator As TranslatorAddIn
Dim oContext As TranslationContext
Dim oOptions As NameValueMap
Dim oDataMedium As DataMedium

Call ConfigureSTEPTranslatorSettings(STEPTranslator, oContext, oOptions, oDataMedium)

'oPath = ThisDoc.Path
oFolder = "C:\Users\STEFANIA\Desktop\Nuova cartella (3)" & "\" & oAsmName & " STEP Files"

If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If

'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'
'look at the files referenced by the assembly
Dim oRefDoc As Document

For Each oRefDoc In oAsmDoc.AllReferencedDocuments
idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"

' If(System.IO.File.Exists(idwPathName)) Then
Dim oSTEPDoc As Document
oSTEPDoc = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)
oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -4)
' oRevNum = oDrawDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value
'oDesc = oRefDoc.iProperties.Value("Project", "Description")
oDesc = oSTEPDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
'********************For Each oRefDoc In oRefDocs

iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "ipt"

'check that model is saved
If(System.IO.File.Exists(iptPathName)) Then

Dim oDrawDoc As PartDocument

oDrawDoc = ThisApplication.Documents.Open(iptPathName, True)

oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName))
End If

'**********************
'
On Error Resume Next
' 'Set the STP target file name
' If oRevNum = Nothing Then
' oDataMedium.FileName = oFolder & "\" & oFileName & ".STP"
oSTEPDoc.SaveAs(oFolder & "\" & oFileName &"_"& Parameter ("sospensione") & oDesc & (".stp") , True)
'
' Else
' oDataMedium.FileName = oFolder & "\" & oFileName & ".STP"
' End If

Call STEPTranslator.SaveCopyAs(oSTEPDoc, oContext, oOptions, oDataMedium)
oRefDoc.Close
On Error Goto 0
' End If
Next
'- - - - - - - - - - - - -

'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
' Dim oAsmDrawingDoc As DrawingDocument
' oAsmDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True)
' oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -4)
' oAsmDrawingRev = oAsmDrawingDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value
'
' On Error Resume Next
' 'Set the PDF target file name
' If oAsmDrawingRev = Nothing Then
' oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & ".pdf"
'
' Else
' oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & " Rev." & oRevNum & ".pdf"
'
' End If
'
' Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
' oAsmDrawingDoc.Close

MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
Shell("explorer.exe " & oFolder,vbNormalFocus)
End Sub

Sub ConfigureSTEPTranslatorSettings(ByRef STEPTranslator As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)

oPath = ThisDoc.Path
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
' Set application protocol.
' 2 = AP 203 - Configuration Controlled Design
' 3 = AP 214 - Automotive Design
oOptions.Value("ApplicationProtocolType") = 3
' Other options...
'oOptions.Value("Author") = ""
'oOptions.Value("Authorization") = ""
'oOptions.Value("Description") = ""
'oOptions.Value("Organization") = ""
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Dim oData As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
oDataMedium.FileName = ThisDoc.PathAndFileName(False) & ".stp"
oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oDataMedium)
End If

oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
End Sub

 

 

0 Likes
Accepted solutions (3)
2,867 Views
33 Replies
Replies (33)
Message 2 of 34

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

I've cleaned your code a bit. As I understand, you want to export every visible part in your assembly to an single STEP file. No export of the entire assembly or any subassemblies. Is this correct?

Try this one:

Option Explicit On
Sub Main()

'check that the active document is an assembly file
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If

Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim sAsmName As String = System.IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullDocumentName )
Dim sFolder As String = "C:\Users\STEFANIA\Desktop\Nuova cartella (3)" & "\" & sAsmName & " STEP Files"

Dim STEPTranslator As TranslatorAddIn
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium  = ThisApplication.TransientObjects.CreateDataMedium
Call ConfigureSTEPTranslatorSettings(STEPTranslator, oContext, oOptions, oDataMedium)

If Not System.IO.Directory.Exists(sFolder) Then
	System.IO.Directory.CreateDirectory(sFolder)
End If

'look at the files referenced by the assembly
Dim oRefDoc As Document
For Each oRefDoc In oAsmDoc.AllReferencedDocuments
	If Not oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Continue For
	'get all occurrences of the referenced file, if one on them is visible - export that file to STEP, otherwise skip
	Dim oOccs As ComponentOccurrencesEnumerator = oAsmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc)
	Dim oOcc As ComponentOccurrence
	Dim bVis As Boolean = False
	For Each oOcc In oOccs
		If oOcc.Visible 
			bVis = True
			Exit For
		End If
	Next
	
	If bVis = False Then
		Continue For 'Next For
	End If
	
	'check that model is saved
	If(System.IO.File.Exists(oRefDoc.FullDocumentName)) Then
		Dim sFilename As String = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullDocumentName)
		Dim sDesc As String = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
		Parameter.Quiet = True
		Dim sSospensione As String = Parameter("sospensione")
		oDataMedium.FileName = sFolder & "\" & sFilename & "_" & sSospensione & sDesc & ".stp"
		
		Try
			Call STEPTranslator.SaveCopyAs(oRefDoc, oContext, oOptions, oDataMedium)
		Catch
			MsgBox("Export of " & oRefDoc.DisplayName & " failed. Continue next one", MsgBoxStyle.Critical)
		End Try
	End If
Next

MessageBox.Show("New Files Created in: " & vbLf & sFolder, "iLogic")
Shell("explorer.exe " & sFolder,vbNormalFocus)
End Sub


Sub ConfigureSTEPTranslatorSettings(ByRef oSTEPTranslator As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
	oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")

	If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
		' Set application protocol.
		' 2 = AP 203 - Configuration Controlled Design
		' 3 = AP 214 - Automotive Design
		oOptions.Value("ApplicationProtocolType") = 3
		' Other options...
		'oOptions.Value("Author") = ""
		'oOptions.Value("Authorization") = ""
		'oOptions.Value("Description") = ""
		'oOptions.Value("Organization") = ""
		oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
		oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
		'oDataMedium.FileName = ThisDoc.PathAndFileName(False) & ".stp"
	End If
End Sub

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 34

leoa.87
Contributor
Contributor

hello, yes you understand what I would like ... I tried the code but on launch it gives me an error "invalid characters in the path" how could i solve?

 

 

System.ArgumentException: Caratteri non validi nel percorso.
   in System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
   in System.IO.Path.GetFileName(String path)
   in System.IO.Path.GetFileNameWithoutExtension(String path)
   in LmiRuleScript.Main()
   in Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   in iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
0 Likes
Message 4 of 34

leoa.87
Contributor
Contributor
ok i solved ... i hacked the code and i replaced

Dim sAsmName As String = System.IO.Path.GetFileNameWithoutExtension (oAsmDoc.FullDocumentName)

with


Dim sAsmName As String = System.IO.Path.GetFileNameWithoutExtension (oAsmDoc.FullFileName)


it works now

Thank you

p.S: I don't want to profit but do you think you could integrate the BOM only parts with excel exports in the same folder?
0 Likes
Message 5 of 34

Ralf_Krieg
Advisor
Advisor

Hello

 

Exporting the BOM is not much work to do.

 

Option Explicit On
Sub Main()

'check that the active document is an assembly file
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If

Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim sAsmName As String = System.IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullFileName )
Dim sFolder As String = "C:\Users\STEFANIA\Desktop\Nuova cartella (3)" & "\" & sAsmName & " STEP Files"

Dim STEPTranslator As TranslatorAddIn
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium  = ThisApplication.TransientObjects.CreateDataMedium
Call ConfigureSTEPTranslatorSettings(STEPTranslator, oContext, oOptions, oDataMedium)

If Not System.IO.Directory.Exists(sFolder) Then
	System.IO.Directory.CreateDirectory(sFolder)
End If

'look at the files referenced by the assembly
Dim oRefDoc As Document
For Each oRefDoc In oAsmDoc.AllReferencedDocuments
	If Not oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Continue For
	'get all occurrences of the referenced file, if one on them is visible - export that file to STEP, otherwise skip
	Dim oOccs As ComponentOccurrencesEnumerator = oAsmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc)
	Dim oOcc As ComponentOccurrence
	Dim bVis As Boolean = False
	For Each oOcc In oOccs
		If oOcc.Visible 
			bVis = True
			Exit For
		End If
	Next
	
	If bVis = False Then
		Continue For 'Next For
	End If
	
	'check that model is saved
	If(System.IO.File.Exists(oRefDoc.FullDocumentName)) Then
		Dim sFilename As String = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullDocumentName)
		Dim sDesc As String = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
		Parameter.Quiet = True
		Dim sSospensione As String = Parameter("sospensione")
		oDataMedium.FileName = sFolder & "\" & sFilename & "_" & sSospensione & sDesc & ".stp"
		
		Try
			Call STEPTranslator.SaveCopyAs(oRefDoc, oContext, oOptions, oDataMedium)
		Catch
			MsgBox("Export of " & oRefDoc.DisplayName & " failed. Continue next one", MsgBoxStyle.Critical)
		End Try
	End If
Next

ExportBOM(oAsmDoc, sFolder)

MessageBox.Show("New Files Created in: " & vbLf & sFolder, "iLogic")
Shell("explorer.exe " & sFolder,vbNormalFocus)
End Sub


Sub ConfigureSTEPTranslatorSettings(ByRef oSTEPTranslator As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
	oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")

	If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
		' Set application protocol.
		' 2 = AP 203 - Configuration Controlled Design
		' 3 = AP 214 - Automotive Design
		oOptions.Value("ApplicationProtocolType") = 3
		' Other options...
		'oOptions.Value("Author") = ""
		'oOptions.Value("Authorization") = ""
		'oOptions.Value("Description") = ""
		'oOptions.Value("Organization") = ""
		oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
		oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
		'oDataMedium.FileName = ThisDoc.PathAndFileName(False) & ".stp"
	End If
End Sub

Sub ExportBOM(ByVal oAsmDoc As AssemblyDocument, ByVal sFolder As String)
	Dim oBOM As Inventor.BOM = oAsmDoc.ComponentDefinition.BOM
	oBOM.PartsOnlyViewEnabled = True
	Dim oBOMView As Inventor.BOMView
	For Each oBOMView In oBOM.BOMViews
		If oBOMView.ViewType=BOMViewTypeEnum.kPartsOnlyBOMViewType Then Exit For	
	Next
	
	If oBOMView IsNot Nothing Then
		oBOMView.Export(sFolder & "\" & "BOM.xls",FileFormatEnum.kMicrosoftExcelFormat)
	End If
	
End Sub

	

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 6 of 34

leoa.87
Contributor
Contributor

 

Hello I the new code gives me an error

 

 

 

 

 

System.NotImplementedException: Non implementato (Eccezione da HRESULT: 0x80004001 (E_NOTIMPL))
in System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
in Inventor.BOMView.Export(String FileName, FileFormatEnum FileFormat, Object Options)
in LmiRuleScript.ExportBOM(AssemblyDocument oAsmDoc, String sFolder)
in LmiRuleScript.Main()
in Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
in iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 7 of 34

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Sorry, can't reproduce the error. Wich version of Inventor are you using?

Is the Thumbnail column visible in the parts only view and can you try disable it before export? Does tihs work? If not, is it possible to post a anonymized sample assembly?


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 8 of 34

leoa.87
Contributor
Contributor
 

 

the version is inventor 2018 and the thumbnails do not export them normally.

your code works if before running the rule I set the detail level on Master if instead it is set on LOD custom it goes in error.

Obviously I only need a parts list for a custom level of detail

Could you force the export of the CUSTOM level of detail BOM only parts for both the assempbly main document and the sub assemblies?

0 Likes
Message 9 of 34

Ralf_Krieg
Advisor
Advisor

Hello

 

Ok, now I can reproduce the error, but have no solution for this.The BOM should export, independent of the active LoD.

 

No, the BOM is not affected by Level of Detail (LoD). LoD is only for reducing used RAM on 32bit systems. So you can't export the BOM of a LoD, cause it doesn't exist. If you want to affect the BOM, you have to set the part/assembly occurrence as "Reference" to "kick it out" the BOM. It would be possible to set this occurrences to reference by an iLogic rule if they are suppressed. The problem is, if they are unsuppressed later, the BOM structure had to change to normal, purchased or inseparable? There's more than one possible choice. In short, not a stable way.

The right way would be to convert the assembly into an iAssembly. There you can define which part to exclude in which version. The change of iAssembly version affects the BOM in the correct way. And you can then define which version to export.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 10 of 34

leoa.87
Contributor
Contributor

 

ok, what you say is right, but I have a general assembly with sub-assemblies and related parts all under ilogic rules.
this in relation to the levels of detail have changes on the bill of materials.

 

if I set custom level of detail on the basis of ilogic rules I only see what interests me because all the components are inactive by ilogic rules and in the bill of materials (parts only) I only see what interests me.
if instead I enable the master level of detail it is as if the ilogic rules for inactivating sub-assemblies and parts no longer have an effect and in fact I see everything in the bill of materials.

I therefore tampered with your code with to make sure that the lod master is forced to get the bill of materials that I am interested in (parts only) export to excel and then retoten in customized level of detail.

the problem that in this way I receive an error message indicating that some subassemblies are set are not set to a custom level of detail but this is false and furthermore ignoring these errors it exports the parts list correctly only.

do you think I can do something?

 

 

Option Explicit On
Sub Main()

'check that the active document is an assembly file
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If
Dim oDoc = ThisApplication.ActiveDocument
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim sAsmName As String = System.IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullFileName )
Dim sFolder As String = "C:\Users\STEFANIA\Desktop\Nuova cartella (3)" & "\" & sAsmName & Parameter("d109") & "Step Files"


Dim STEPTranslator As TranslatorAddIn
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium  = ThisApplication.TransientObjects.CreateDataMedium
Call ConfigureSTEPTranslatorSettings(STEPTranslator, oContext, oOptions, oDataMedium)

If Not System.IO.Directory.Exists(sFolder) Then
	System.IO.Directory.CreateDirectory(sFolder)
End If

	'sFolder = "C:\Users\STEFANIA\Desktop\Nuova cartella (3)"& Parameter"d118" 
		

'look at the files referenced by the assembly
Dim oRefDoc As Document
For Each oRefDoc In oAsmDoc.AllReferencedDocuments
	If Not oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Continue For
	'get all occurrences of the referenced file, if one on them is visible - export that file to STEP, otherwise skip
	Dim oOccs As ComponentOccurrencesEnumerator = oAsmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc)
	Dim oOcc As ComponentOccurrence
	Dim bVis As Boolean = False
	For Each oOcc In oOccs
		If oOcc.Visible 
			bVis = True
			Exit For
		End If
	Next
	
	If bVis = False Then
		Continue For 'Next For
	End If
	
	'check that model is saved
	If(System.IO.File.Exists(oRefDoc.FullDocumentName)) Then
		Dim sFilename As String = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullDocumentName)
		Dim sDesc As String = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
		Parameter.Quiet = True
		Dim sSospensione As String = Parameter("sospensione")
		Dim srif As String = Parameter("d109")
		oDataMedium.FileName = sFolder & "\" & sFilename & "_" & sSospensione & srif & sDesc & ".stp"
		
		Try
			Call STEPTranslator.SaveCopyAs(oRefDoc, oContext, oOptions, oDataMedium)
		Catch
			MsgBox("Export of " & oRefDoc.DisplayName & " failed. Continue next one", MsgBoxStyle.Critical)
		End Try
	End If
Next

MessageBox.Show("New Files Created in: " & vbLf & sFolder, "iLogic")
Shell("explorer.exe " & sFolder,vbNormalFocus)


		Dim oDock As Document = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = oDock.ComponentDefinition
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Principale").activate
oDock.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Principale").activate



Dim ExportSheet = sFolder  & "\"  & "Parts Only " & Parameter("d109") & ".xls"

'oAsmDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM


'' Export the BOM view 
Dim oPartsOnlyBOMView As BOMView
oPartsOnlyBOMView = oBOM.BOMViews.Item("Solo parti")
oPartsOnlyBOMView.Export(ExportSheet, kMicrosoftExcelFormat)


Try
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("View1").activate 
Catch
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("View1")
End Try
Try
oDock.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Livello di dettaglio1").activate
Catch
oDock.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations.Add("Livello di dettaglio1")
End Try
		




End Sub


Sub ConfigureSTEPTranslatorSettings(ByRef oSTEPTranslator As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
	oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")

	If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
		' Set application protocol.
		' 2 = AP 203 - Configuration Controlled Design
		' 3 = AP 214 - Automotive Design
		oOptions.Value("ApplicationProtocolType") = 3
		' Other options...
		'oOptions.Value("Author") = ""
		'oOptions.Value("Authorization") = ""
		'oOptions.Value("Description") = ""
		'oOptions.Value("Organization") = ""
		oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
		oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
		'oDataMedium.FileName = ThisDoc.PathAndFileName(False) & ".stp"
		
		
		
	End If
End Sub

 

0 Likes
Message 11 of 34

leoa.87
Contributor
Contributor


if I put this code inside yours, I can get the basic list with the components I need (managed by other ilogic rules)
but this rule reports me an error for each subassembly that is inside.

(Rule error: Parameters xxx.iam, document: xxx.iam

Component.IsActive: Could not change the suppression status of the lining component xxx: 1.
The active level of detail in xxx is not a custom level of detail.

giving ok. it goes on and carries out the export of the list but it is very annoying.

how could i solve?

 

 

Dim oDock As Document = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = oDock.ComponentDefinition
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Principale").activate
oDock.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Principale").activate



Dim ExportSheet = sFolder  & "\"  & "Parts Only " & Parameter("d109") & ".xls"

'oAsmDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM


'' Export the BOM view 
Dim oPartsOnlyBOMView As BOMView
oPartsOnlyBOMView = oBOM.BOMViews.Item("Solo parti")
oPartsOnlyBOMView.Export(ExportSheet, kMicrosoftExcelFormat)


Try
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("View1").activate 
Catch
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("View1")
End Try
Try
oDock.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Livello di dettaglio1").activate
Catch
oDock.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations.Add("Livello di dettaglio1")
End Try
0 Likes
Message 12 of 34

Ralf_Krieg
Advisor
Advisor

Hello

 

As I can see, iLogic's Component.IsActive sets the status of a component to suppressed and also sets the BOM structure to reference for this occurrences. That's why the BOM shows correct parts only view.

 

Your subassemblies seems to have a write protected LoD active. So setting component status by iLogic is not allowed. You have to switch to a writeable LoD in the subassemblies before.

Can't give you more details, cause nothing of this is shown in your code. It's very hard to follow you, but I'll try my best. 🙂


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 13 of 34

leoa.87
Contributor
Contributor

hi, thanks for your support.

as regards the LODs, in the sub-assemblies I simply set a custom LOD "Level of detail1" this same level is set on all the .iams present.

So I do not understand why he creates that error for me.

Are there any ways to set up an LOD without write protection?

0 Likes
Message 14 of 34

Ralf_Krieg
Advisor
Advisor

Hello

 

Maybe this script can help you. It checks in the main assembly and recursive in all subassemblies if a Level of Detail named "LoD" exists and activate it. If there's not a Level of Detail "LoD" it creates one and then activate it.

The name of the LoD can be changed in second line.

 

Sub Main
	Dim sLoDName As String = "LoD" 
	
	Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
	Dim oOccs As Inventor.ComponentOccurrences=oAsmDoc.ComponentDefinition.Occurrences 

	LoD(oAsmDoc, sLoDName)
	LoD(oOccs, sLoDName)

	MsgBox("done")

End Sub

Private Sub LoD(ByVal oOccs As ComponentOccurrences, ByVal sLoDName As String)
	
	Dim oCompDef As AssemblyComponentDefinition
	Dim oOcc As Inventor.ComponentOccurrence

	For Each oOcc In oOccs
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			oCompDef= oOcc.Definition			
			Dim oLoD As LevelOfDetailRepresentation
			For Each oLod In oCompDef.RepresentationsManager.LevelOfDetailRepresentations
				If oLoD.Name = sLoDName Then 
					Exit For
				End If
				oLoD=Nothing
			Next
	
			If oLoD Is Nothing Then
				oLoD = oCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add(sLoDName)
			End If
			oOcc.SetLevelOfDetailRepresentation(sLoDName, True)
			
			LoD(oOcc.Definition.Occurrences,sLoDName )
		End If
	Next
End Sub

Private Sub LoD(ByVal oAsmDoc As AssemblyDocument, ByVal sLoDName As String)
	Dim oCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition 
	Dim oLod As LevelOfDetailRepresentation
	For Each oLod In oCompDef.RepresentationsManager.LevelOfDetailRepresentations
		If oLod.Name = sLoDName Then 
			oLod.Activate
			Exit For
		End If
		oLod=Nothing
	Next
	
	If oLod Is Nothing Then
		oLod = oCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add(sLoDName)
	End If
	If Not oCompDef.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name=sLoDName Then
		oCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item(sLoDName).Activate
	End If
End Sub

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 15 of 34

leoa.87
Contributor
Contributor

 

hello, I need your kind help once again ...
could you also include the dwg export of the active files in the assembly?

0 Likes
Message 16 of 34

Ralf_Krieg
Advisor
Advisor

Hello

 

This snippet can do the export

Sub PublishDWG(ByVal oDoc As Document,ByVal sFolder As String, ByVal sFileName As String, sSospensione As String,ByVal srif As String, ByVal sDesc As String)
    ' Get the DWG translator Add-In.
    Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
   'Create translation context
    Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism
    ' Create a NameValueMap object
    Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
    ' Create a DataMedium object
    Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
    'Set the destination file name
    oDataMedium.FileName = oDataMedium.FileName = sFolder & "\" & sFilename & "_" & sSospensione & srif & sDesc & ".dwg"
    'Publish document.
    Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

 

You have to call it from your main sub

PublishDWG(oRefDoc,sFolder,sFileName,sSospensione,srif,sDesc)

R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 17 of 34

leoa.87
Contributor
Contributor


Hello,
i can't get it to work

this is currently my rule.
I would also like to export the individual dwg files.

would you kindly help me to integrate it into this rule?

 

Sub Main()

'check that the active document is an assembly file
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If
Dim oDoc = ThisApplication.ActiveDocument
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim sAsmName As String = System.IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullFileName )
Dim sFolder As String = "C:\Users\l.azzariti\Desktop\Output" & "\" & sAsmName & "_" & Parameter("RIF_CMA") & Parameter("RIF_ID") & "Step"


Dim STEPTranslator As TranslatorAddIn
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium  = ThisApplication.TransientObjects.CreateDataMedium
Call ConfigureSTEPTranslatorSettings(STEPTranslator, oContext, oOptions, oDataMedium)

If Not System.IO.Directory.Exists(sFolder) Then
	System.IO.Directory.CreateDirectory(sFolder)
End If

	
		

'look at the files referenced by the assembly
Dim oRefDoc As Document
For Each oRefDoc In oAsmDoc.AllReferencedDocuments
	If Not oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Continue For
	'get all occurrences of the referenced file, if one on them is visible - export that file to STEP, otherwise skip
	Dim oOccs As ComponentOccurrencesEnumerator = oAsmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc)
	Dim oOcc As ComponentOccurrence
	Dim bVis As Boolean = False
	For Each oOcc In oOccs
		If oOcc.Visible 
			bVis = True
			Exit For
		End If
	Next
	
	If bVis = False Then
		Continue For 'Next For
	End If
	
	'check that model is saved
	If(System.IO.File.Exists(oRefDoc.FullDocumentName)) Then
		Dim sFilename As String = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullDocumentName)
		Dim sDesc As String = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
		Parameter.Quiet = True
		Dim sRIF_CMA As String = Parameter("RIF_CMA")
		Dim sRIF_ID As String = Parameter("RIF_ID")
		oDataMedium.FileName = sFolder & "\" & sFilename & "_" & sRIF_CMA & "_" & sRIF_ID & sDesc & ".stp"
		
		Try
			Call STEPTranslator.SaveCopyAs(oRefDoc, oContext, oOptions, oDataMedium)
		Catch
			MsgBox("Export of " & oRefDoc.DisplayName & " failed. Continue next one", MsgBoxStyle.Critical)
		End Try
	End If
Next

MessageBox.Show("New Files Created in: " & vbLf & sFolder, "iLogic")
Shell("explorer.exe " & sFolder,vbNormalFocus)


		Dim oDock As Document = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = oDock.ComponentDefinition
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Principale").activate
oDock.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Principale").activate



Dim ExportSheet = sFolder  & "\"  & "Distinta" & "_" & Parameter("RIF_CMA") & "_" & Parameter ("RIF_ID") & ".xls"

'oAsmDoc = ThisApplication.ActiveDocument''''
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM


'' Export the BOM view 
Dim oPartsOnlyBOMView As BOMView
oPartsOnlyBOMView = oBOM.BOMViews.Item("Solo parti")
oPartsOnlyBOMView.Export(ExportSheet, kMicrosoftExcelFormat)


Try
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Vista1").activate 
Catch
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("Vista1")
End Try
Try
oDock.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Livello di dettaglio1").activate
Catch
oDock.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations.Add("Livello di dettaglio1")
End Try
		




End Sub


Sub ConfigureSTEPTranslatorSettings(ByRef oSTEPTranslator As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
	oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")

	If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
		' Set application protocol.
		' 2 = AP 203 - Configuration Controlled Design
		' 3 = AP 214 - Automotive Design
		oOptions.Value("ApplicationProtocolType") = 3
		' Other options...
		'oOptions.Value("Author") = ""
		'oOptions.Value("Authorization") = ""
		'oOptions.Value("Description") = ""
		'oOptions.Value("Organization") = ""
		oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
		oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
		'oDataMedium.FileName = ThisDoc.PathAndFileName(False) & ".stp"
		
		
		
	End If
End Sub

 

 

 

0 Likes
Message 18 of 34

Ralf_Krieg
Advisor
Advisor

Hello

 

I have sorted your code a little bit and added the DWG export. I'm not able to test it right now.

Please try this and post if errors occur.

Sub Main()

'check that the active document is an assembly file
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If
'Dim oDoc = ThisApplication.ActiveDocument
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim sAsmName As String = System.IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullFileName )
Dim sFolder As String = "C:\Users\l.azzariti\Desktop\Output" & "\" & sAsmName & "_" & Parameter("RIF_CMA") & Parameter("RIF_ID") & "Step"


Dim STEPTranslator As TranslatorAddIn
Dim oSTPContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oSTPOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oSTPDataMedium As DataMedium  = ThisApplication.TransientObjects.CreateDataMedium
Call ConfigureSTEPTranslatorSettings(STEPTranslator, oSTPContext, oSTPOptions)

Dim DWGTranslator As TranslatorAddIn
Dim oDWGContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oDWGOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDWGDataMedium As DataMedium  = ThisApplication.TransientObjects.CreateDataMedium
Call ConfigureDWGTranslatorSettings(DWGTranslator, oDWGContext)

If Not System.IO.Directory.Exists(sFolder) Then
	System.IO.Directory.CreateDirectory(sFolder)
End If
	

'look at the files referenced by the assembly
Dim oRefDoc As Document
For Each oRefDoc In oAsmDoc.AllReferencedDocuments
	If Not oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Continue For
	'get all occurrences of the referenced file, if one on them is visible - export that file to STEP, otherwise skip
	Dim oOccs As ComponentOccurrencesEnumerator = oAsmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc)
	Dim oOcc As ComponentOccurrence
	Dim bVis As Boolean = False
	For Each oOcc In oOccs
		If oOcc.Visible 
			bVis = True
			Exit For
		End If
	Next
	
	If bVis = False Then
		Continue For 'Next For
	End If
	
	'check that model is saved
	If(System.IO.File.Exists(oRefDoc.FullDocumentName)) Then
		Dim sFilename As String = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullDocumentName)
		Dim sDesc As String = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
		Parameter.Quiet = True
		Dim sRIF_CMA As String = Parameter("RIF_CMA")
		Dim sRIF_ID As String = Parameter("RIF_ID")
		oSTPDataMedium.FileName = sFolder & "\" & sFilename & "_" & sRIF_CMA & "_" & sRIF_ID & sDesc & ".stp"
		oDWGDataMedium.FileName = sFolder & "\" & sFilename & "_" & sRIF_CMA & "_" & sRIF_ID & sDesc & ".dwg"
		
		Try
			Call STEPTranslator.SaveCopyAs(oRefDoc, oSTPContext, oSTPOptions, oSTPDataMedium)
		Catch
			MsgBox("Export of " & oRefDoc.DisplayName & " to STP failed. Continue next one", MsgBoxStyle.Critical)
		End Try
		Try
			Call DWGTranslator.SaveCopyAs(oRefDoc, oDWGContext, oDWGOptions, oDWGDataMedium)
		Catch
			MsgBox("Export of " & oRefDoc.DisplayName & " to DWG failed. Continue next one", MsgBoxStyle.Critical)
		End Try
	End If
Next

MessageBox.Show("New Files Created in: " & vbLf & sFolder, "iLogic")
Shell("explorer.exe " & sFolder,vbNormalFocus)

Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim oRepMgr As RepresentationsManager =oAsmCompDef.RepresentationsManager 
oRepMgr.DesignViewRepresentations.Item("Principale").activate
oRepMgr.LevelofDetailRepresentations("Principale").activate

Dim ExportSheet = sFolder  & "\"  & "Distinta" & "_" & Parameter("RIF_CMA") & "_" & Parameter ("RIF_ID") & ".xls"

Dim oBOM As BOM
oBOM = oAsmDoc.ComponentDefinition.BOM

'' Export the BOM view 
Dim oPartsOnlyBOMView As BOMView
oPartsOnlyBOMView = oBOM.BOMViews.Item("Solo parti")
oPartsOnlyBOMView.Export(ExportSheet, kMicrosoftExcelFormat)

Try
	oRepMgr.DesignViewRepresentations.Item("Vista1").Activate 
Catch
	oRepMgr.DesignViewRepresentations.Add("Vista1")
End Try
Try
	oRepMgr.LevelofDetailRepresentations("Livello di dettaglio1").activate
Catch
	oRepMgr.LevelofDetailRepresentations.Add("Livello di dettaglio1")
End Try
		
End Sub


Sub ConfigureSTEPTranslatorSettings(ByRef oSTEPTranslator As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap)
	oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")

	If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
		' Set application protocol.
		' 2 = AP 203 - Configuration Controlled Design
		' 3 = AP 214 - Automotive Design
		oOptions.Value("ApplicationProtocolType") = 3
		' Other options...
		'oOptions.Value("Author") = ""
		'oOptions.Value("Authorization") = ""
		'oOptions.Value("Description") = ""
		'oOptions.Value("Organization") = ""
		oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	End If
End Sub

Sub ConfigureDWGTranslatorSettings(ByRef oDWGTranslator As TranslatorAddIn, ByRef oContext As TranslationContext)
	oDWGTranslator = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
End Sub

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 19 of 34

leoa.87
Contributor
Contributor


thanks it works ...
but the dwg serves me as a flat model, can you add it as a dwg?

0 Likes
Message 20 of 34

Ralf_Krieg
Advisor
Advisor

Hello

 

Sorry, don't understand what you mean. If you export a part file to a DWG, it will save the 3D model in model space of the dwg. It will not create a Inventor drawing document, place views, add all needed dimensions, fill titleblock or anything else and export it to a DWG file. Or do you mean something different?


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes