Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've got a rule that creates a view, hides certain parts, creates simplified part, and match iProperties of the assembly. It works well with smaller assemblies but when it runs on larger assemblies the simplified part creation takes a while and then it doesn't save the file and copy the iProperties over. Is there any way to keep it from moving forward at line 114 until the earlier part of the rule is completed?
Class iRule
Public oView As DrawingView
Public oSheet As Sheet
Public oPartslist As PartsList
Public oCompDef As ComponentDefinition
Public oNewFullName As String
Sub Main()
Q = MessageBox.Show("You are about to create an Asset View and Simplified Part this may take a few minutes to complete. Click Cancel to stop the rule from running.", "Simplified Part", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
If Q = vbOK Then 'Action
ElseIf Q = vbCancel Then
Exit Sub
End If
oSrcDWG = ThisApplication.ActiveDocument
oCompDef = oSrcDWG.ComponentDefinition
Try
oCompDef.RepresentationsManager.DesignViewRepresentations.Item("ASSET VIEW").Activate
SimplifiedPartCreation(oSrcDWG)
CopyIproperties(oSrcDWG)
Catch
ViewCreation(oSrcDWG)
PartTurnOFF(oSrcDWG)
CopyIproperties(oSrcDWG)
SimplifiedPartCreation(oSrcDWG)
CopyIproperties(oSrcDWG)
End Try
'CopyIproperties(oSrcDWG)
End Sub
Sub ViewCreation(oSrcDWG)
'Creates Representation
Dim oviewrep As DesignViewRepresentation
Try
oCompDef.RepresentationsManager.DesignViewRepresentations.Item("ASSET VIEW").Activate
Catch
oviewrep = oCompDef.RepresentationsManager.DesignViewRepresentations.Add("ASSET VIEW")
'Activate new View Rep
oviewrep.activate
End Try
'Turn off ALL object visibility
ThisApplication.ActiveDocument.ObjectVisibility.AllWorkfeatures = False
ThisApplication.ActiveDocument.ObjectVisibility.ConstructionSurfaces = False
ThisApplication.ActiveDocument.ObjectVisibility.Sketches = False
ThisApplication.ActiveDocument.ObjectVisibility.Sketches3D = False
ThisApplication.ActiveDocument.ObjectVisibility.SketchDimensions = False
ThisApplication.ActiveDocument.ObjectVisibility.Annotations3D = False
If oSrcDWG.DocumentType = kAssemblyDocumentObject Then
ThisApplication.ActiveDocument.ObjectVisibility.WeldmentSymbols = False
ThisApplication.ActiveDocument.ObjectVisibility.Welds = False
End If
iLogicVb.UpdateWhenDone = True
End Sub
Sub PartTurnOFF(oSrcDWG)
'Hides Parts in assembly for view
Dim assemblyDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition
Dim occ As Inventor.ComponentOccurrence
For Each occ In assemblyDef.Occurrences.AllLeafOccurrences
Dim refDoc As PartDocument = occ.Definition.Document
'MessageBox.Show(occ.Name.ToString, "Title")
'MessageBox.Show(iProperties.Value(occ.Name,"Project", "Part Number").ToString, "Title")
''ADD MORE IF STATEMENTS ON OTHER PARTS TO REMOVE
If iProperties.Value(occ.Name, "Project", "Vendor").Contains("HARDWARE") Then
occ.Visible = False
Else If iProperties.Value(occ.Name, "Project", "DESCRIPTION").Contains("CLAMP") Then
occ.Visible = False
Else If iProperties.Value(occ.Name, "Project", "DESCRIPTION").Contains("GASKET") Then
occ.Visible = False
'USE TO TURN PARTS ON
'occ.Visible = True
Else If iProperties.Value(occ.Name, "Project", "DESCRIPTION").Contains("PLUG") Then
occ.Visible = False
End If
Next
End Sub
Sub SimplifiedPartCreation(oSrcDWG)
'Creates Simplified part
Try
Dim oFileName As String = IO.Path.GetFileNameWithoutExtension(oSrcDWG.FullFileName)
Dim oPartDoc As PartDocument
Dim g_App As Inventor.InventorServer = ThisApplication
Dim AssDoc As Inventor.AssemblyDocument = ThisDoc.Document
'Create a new part document that will be the shrinkwrap substitute
oPartDoc = g_App.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
Dim oPartDef As PartComponentDefinition
oPartDef = oPartDoc.ComponentDefinition
Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(AssDoc.FullDocumentName)
' Set various shrinkwrap related options
oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
Call oDerivedAssemblyDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchNone)
Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(DerivedGeometryRemovalEnum.kDerivedRemoveNone)
Dim oDerivedAss As DerivedAssemblyComponent
oDerivedAss = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
' Call oDerivedAss.SuppressLinkToFile(True)
' Save the part
Dim partname As String = ThisDoc.PathAndFileName(False) & " - SIMPLIFIED.ipt"
ThisApplication.ActiveView.Fit
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute
Call oPartDoc.SaveAs(partname, False)
Catch ex As Exception
ErrorMessage = "Error creating ipt file."
End Try
End Sub
Sub CopyIproperties(ByVal oSrcDWG As Document)
'Used to Match iProperties to newly created part.
toDoc = ThisApplication.ActiveDocument
Dim fromPs As PropertySet
For Each fromPs In oSrcDWG.PropertySets
Dim toPs As PropertySet
If Not toDoc.PropertySets.PropertySetExists(fromPs.InternalName) Then
toPs = toDoc.PropertySets.Add(fromPs.Name, fromPs.InternalName)
Else
toPs = toDoc.PropertySets(fromPs.InternalName)
End If
Dim fromP
For Each fromP In fromPs
Dim toP
On Error Resume Next
toP = toPs.ItemByPropId(fromP.PropId)
If Err.Number <> 0 Then
toP = toPs.Add(fromP.Value, fromP.Name, fromP.PropId)
Else
toP = toPs(fromP.Name)
If fromP.Value <> Nothing Then
toP.Value = fromP.Value
End If
End If
On Error GoTo 0
Next
Next
ThisApplication.ActiveView.Fit
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute
i = MessageBox.Show("Your Simplified part has been completed."& vbCrLf &"Verify your model is correct and finish these steps"& vbCrLf &" - Suppress link with base component"& vbCrLf &" - Check simplified part into the Vault"& vbCrLf &" - Publish Asset", "Asset Creation", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End Sub
End Class
Solved! Go to Solution.