12-18-2020
01:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
12-18-2020
01:10 AM
Thanks for your help, there was some issue in splitting geometry. However, I twisted it as per my requirement. Now it's working perfectly.
Here below code which I exactly used:
Sub Main() Dim oTg As TransientGeometry = ThisApplication.TransientGeometry Dim doc As Document = ThisDoc.Document Dim ass As AssemblyDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject) ass.ComponentDefinition.Occurrences.Add(doc.FullFileName, oTg.CreateMatrix()) Dim path As String = IO.Path.GetDirectoryName(doc.FullFileName) Dim filename As String = IO.Path.GetFileNameWithoutExtension(doc.FullFileName) filename = filename & ".iam" filename = IO.Path.Combine(path, filename) ass.SaveAs(filename, True) ass.Close(True) Dim doc2 As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject) Dim derivedDef As DerivedAssemblyDefinition = doc2.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(filename) derivedDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsSingleBodyNoSeams derivedDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchAll) Dim derivedPart As DerivedAssemblyComponent = doc2.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(derivedDef) Dim filename2 As String = IO.Path.GetFileNameWithoutExtension(doc.FullFileName) filename2 = filename2 & "_closed.ipt" filename2 = IO.Path.Combine(path, filename2) doc2.SaveAs(filename2, True) doc2.Close(True) Dim partName1 As String = doc.FullFileName Dim partName2 As String = filename2 Dim partDoc As PartDocument = createDiff(partName2, partName1) Dim massProps As MassProperties = partDoc.ComponentDefinition.MassProperties Dim uom As UnitsOfMeasure = partDoc.UnitsOfMeasure Dim defaultLength As String = uom.GetStringFromType(uom.LengthUnits) Dim volume As String = uom.GetStringFromValue(partDoc.ComponentDefinition.MassProperties.Volume, defaultLength & "^3") MsgBox(volume) End Sub Public Function createDiff(fileName1 As String, fileName2 As String) As PartDocument Dim doc As PartDocument = ThisApplication.Documents.Open(fileName1, True) Dim fileInfo As IO.FileInfo = New IO.FileInfo(doc.FullFileName) Dim newFileName = IO.Path.Combine( fileInfo.DirectoryName, fileInfo.Name.Replace(fileInfo.Extension, "") + "_dif" + fileInfo.Extension) doc.SaveAs(newFileName, False) Dim derivedPartDef As DerivedPartUniformScaleDef derivedPartDef = doc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(fileName2) derivedPartDef.BodyAsSolidBody = True Dim derivedPart As DerivedPartComponent derivedPart = doc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(derivedPartDef) 'create a collection Dim oColl As ObjectCollection oColl = ThisApplication.TransientObjects.CreateObjectCollection Dim splitTool As SurfaceBody = doc.ComponentDefinition.SurfaceBodies.Item(2) oColl.Add(splitTool) splitTool.Visible = False Dim body As SurfaceBody = doc.ComponentDefinition.SurfaceBodies.Item(1) Try doc.ComponentDefinition.Features.CombineFeatures.Add(body, oColl,PartFeatureOperationEnum.kCutOperation, ) Catch End Try doc.ActiveRenderStyle = doc.RenderStyles.Item("Green") ThisApplication.ActiveView.Update() Return doc End Function
Bhavik Suthar