- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Forum!
I am trying to measure from a component occurrence inside a sub assembly to the XZ work plane on the main assembly. The component occurrence gets selected by the user and has a work surface called "Face0". My goal is to measure from "Face0" of the selected occurrence to "XZ Plane".
Here's the code I've written:
Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument Dim oAsmComp As AssemblyComponentDefinition = oAsm.ComponentDefinition Dim Splice As ComponentOccurrence Splice = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a splice plate") Dim Height As Double 'Height = Measure.MinimumDistance(Splice, "Face0", "", "GROUND PLANE") Height = Measure.MinimumDistance(Splice, "Face0", oAsm, "GROUND PLANE")
This code currently gets an error not sure why. I was wondering if someone has worked on a code similar to this before.
The occurrence part is inside "Assembly1" and I am running the code from "Assembly2" as shown in the snippet below
Thanks,
Felix
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It's strange, but it seems there is no way to use Measure.MinimumDistance to measure the distance between an entity in a component and an entity in the top level assembly...
Then we'll have to use more advanced API functionality:
Sub Main Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument Dim oAsmComp As AssemblyComponentDefinition = oAsm.ComponentDefinition Dim oUM As UnitsOfMeasure = oAsm.UnitsOfMeasure Dim Splice As ComponentOccurrence Splice = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a splice plate") 'Create a proxy for Face0 (The face in the context of the assembly) Dim oFace0 As Object Splice.CreateGeometryProxy(GetNamedEntity(Splice.Definition.Document, "Face0"), oFace0) 'Get the XZ Plane of the assembly Dim oXZplane As WorkPlane = oAsmComp.WorkPlanes.Item("XZ Plane") 'Measure distance Dim Height As Double = ThisApplication.MeasureTools.GetMinimumDistance(oFace0, oXZplane) 'Convert distance from database units to default units of the document Height = oUM.ConvertUnits(Height, UnitsTypeEnum.kDatabaseLengthUnits, oUM.LengthUnits) 'Return the value in a messagebox just to control that it's right MsgBox(Height) End Sub Public Function GetNamedEntity(doc As Inventor.Document, name As String) As Object Dim attribMgr As AttributeManager = doc.AttributeManager Dim objsFound As ObjectCollection objsFound = attribMgr.FindObjects("iLogicEntityNameSet", "iLogicEntityName", name) If objsFound.Count > 0 Then Return(objsFound.Item(1)) Else Return(Nothing) End If End Function
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Jhoel,
This worked great! Is there any way to measure the Y distance? That's the dimension most crucial for me and I thought that the minimum distance would give me that dimension. Either way thank you for helping me out!
Thanks,
Felix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I believe something like this should give you the Y-value:
Sub Main Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument Dim oAsmComp As AssemblyComponentDefinition = oAsm.ComponentDefinition Dim oUM As UnitsOfMeasure = oAsm.UnitsOfMeasure Dim Splice As ComponentOccurrence Splice = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a splice plate") 'Create a proxy for Face0 (The face in the context of the assembly) Dim oFace0 As Object Splice.CreateGeometryProxy(GetNamedEntity(Splice.Definition.Document, "Face0"), oFace0) 'Get the XZ Plane of the assembly Dim oXZplane As WorkPlane = oAsmComp.WorkPlanes.Item("XZ Plane") 'Measure distance Dim oNV As NameValueMap Dim Height As Double Call ThisApplication.MeasureTools.GetMinimumDistance(oFace0, oXZplane, , , oNV) Dim oVector As Vector = oNV.Item("ClosestPointOne").VectorTo(oNV.Item("ClosestPointTwo")) 'Convert distance from database units to default units of the document Height = oUM.ConvertUnits(Abs(oVector.Y), UnitsTypeEnum.kDatabaseLengthUnits, oUM.LengthUnits) 'Return the value in a messagebox just to control that it's right MsgBox(Height) End Sub Public Function GetNamedEntity(doc As Inventor.Document, name As String) As Object Dim attribMgr As AttributeManager = doc.AttributeManager Dim objsFound As ObjectCollection objsFound = attribMgr.FindObjects("iLogicEntityNameSet", "iLogicEntityName", name) If objsFound.Count > 0 Then Return(objsFound.Item(1)) Else Return(Nothing) End If End Function
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Has anyone since found a way to use Measure.MinimumDistance to measure the distance between an entity in a component and an entity in the top level assembly? Measure.MinimumDistance works really well for what I'm writing, since you don't need to define what type of geometry/feature you are measuring between, i.e. you just have to specify their names.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Russel,
maybe a trick can help you:
Place a dummy component (as reference part, no impact for BOM and weight, can be an empty file without geometry) at the origin to your assy and measure to this!?! Maybe not the best , but will be totally easy without that bunch of coding. ![]()
Kay (Principal CAD-Consultant)