iLogic Measure Inside Assembly

iLogic Measure Inside Assembly

felix.cortes5K3Y2
Advocate Advocate
1,746 Views
5 Replies
Message 1 of 6

iLogic Measure Inside Assembly

felix.cortes5K3Y2
Advocate
Advocate

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

iLogic Snip.png

 

Thanks, 

Felix

0 Likes
Accepted solutions (1)
1,747 Views
5 Replies
Replies (5)
Message 2 of 6

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @felix.cortes5K3Y2 

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
0 Likes
Message 3 of 6

felix.cortes5K3Y2
Advocate
Advocate

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

0 Likes
Message 4 of 6

JhoelForshav
Mentor
Mentor

Hi @felix.cortes5K3Y2 

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

 

0 Likes
Message 5 of 6

Russell.BrownVEZMW
Contributor
Contributor

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

0 Likes
Message 6 of 6

Kay_Rethmeier
Advocate
Advocate

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. 😁

 

Cheers
Kay (Principal CAD-Consultant)
0 Likes