- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Some time a go i wrote this blog post. Its about Comparing part geometry with iLogic. I figured if you fill all holes and then compare it with the original file you will get a part that is the inner volume. So i changed my original blog post. now it will give you a volume (as a part and as a message). The only down side is that it creates some extra files. it starts by creating a assembly wit only the original part. That is assembly is used to create a simplified model and fill all holes. then my original code go's to work and creates a diff file.
Try it and let me know what you think..
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) derivedPart.BreakLinkToFile() 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 = False Dim derivedPart As DerivedPartComponent derivedPart = doc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(derivedPartDef) derivedPart.BreakLinkToFile() Dim splitTool As SurfaceBody = doc.ComponentDefinition.WorkSurfaces.Item(1)._SurfaceBody splitTool.Visible = False Dim body As SurfaceBody = doc.ComponentDefinition.SurfaceBodies.Item(1) Try doc.ComponentDefinition.Features.SplitFeatures.TrimSolid(splitTool, body, False) Catch ex As Exception doc.ComponentDefinition.Features.SplitFeatures.TrimSolid(splitTool, body, True) End Try Try doc.ActiveRenderStyle = doc.RenderStyles.Item("Green") Catch ex As Exception End Try ThisApplication.ActiveView.Update() 'doc.Save() 'doc.Close(True) Return doc End Function
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com