Trying to add hole centers from horizontal frame members to verticals

Trying to add hole centers from horizontal frame members to verticals

dhanna
Enthusiast Enthusiast
425 Views
3 Replies
Message 1 of 4

Trying to add hole centers from horizontal frame members to verticals

dhanna
Enthusiast
Enthusiast

Good morning;

I am trying to place workpoints on to frame members based on locations of screw splines of the horizontal frame members. I wrote a rule that creates a workaxis at a cylindrical face of filtered size, that mostly works ( I tried to name each workaxis, but that fails, and is not part of current problem I'm inquiring about)

 

I attached a jpg of an experimental frame, the frame I intend to use it on is much more complex.

 

I've tried different objects, parameters, just can't see which way to go . Any suggestions or better process would be most appreciated, thank you in advance.

 

<code>

Sub Main
' Get the active assembly.
Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument

'On Error Resume Next
'MessageBox.Show(oAssyDoc.FullDocumentName, "Title")
Call TraverseAssembly(oAssyDoc.ComponentDefinition.Occurrences)

End Sub

Sub TraverseAssembly(ByRef oOccs As ComponentOccurrences)
' Iterate through all of the occurrence in this collection
Dim oOcc As ComponentOccurrence

' On Error Resume Next

For Each oOcc In oOccs

If oOcc.DefinitionDocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
'' Recursively Call Sub If needed

Call TraverseAssembly(oOcc.SubOccurrences)
Else If oOcc.Definition.Document.propertysets.item("Design Tracking Properties").item("Stock Number").VALUE = "Horizontal" Then
'oOcc.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject And oOcc.SurfaceBodies.Count >0 Then
CreateHoles(oOcc.Definition.SurfaceBodies(1))
End If

Next

End Sub

Sub CreateHoles(ByVal SrfcBd As Inventor.SurfaceBody)


Dim PrtCmp As Inventor.PartComponentDefinition

PrtCmp = SrfcBd.Parent


Dim oAxis As Dictionary(Of Object, Object)
Dim oAxs As Inventor.WorkAxis
Dim oNrml As Inventor.UnitVector
Dim oNrmlRev As Inventor.UnitVector
Dim ZLength As Double
Dim sktch As PlanarSketch
Dim oPln As Object
Dim CNTRD As Object
Dim EndFc As Inventor.Face
Dim StrtFc As Inventor.Face
Dim oTG As TransientGeometry
Dim Indx As Long
Dim CntrPt As Inventor.Point= PrtCmp.MassProperties.CenterOfMass

oTG = ThisApplication.TransientGeometry

oAxis = New Dictionary(Of Object, Object)

Call GetAxes(PrtCmp, oAxis)

sktch = PrtCmp.Features.ExtrudeFeatures(1).Definition.Profile(1)(1).SketchEntity.Parent
oPln = sktch.PlanarEntity

EndFc = PrtCmp.Features.ExtrudeFeatures(1).Faces.Item(PrtCmp.Features.ExtrudeFeatures(1).Faces.Count)
StrtFc = PrtCmp.Features.ExtrudeFeatures(1).Faces.Item(PrtCmp.Features.ExtrudeFeatures(1).Faces.Count - 1)

Dim repStrt As Inventor.Plane
Dim repEnd As Inventor.Plane

Dim EndPl = PrtCmp.WorkPlanes("End Plane")
Dim StrtPl = PrtCmp.WorkPlanes("Start Plane")

repStrt = oTG.CreatePlane(CntrPt,StrtPl.Plane.Normal.AsVector)
repEnd = oTG.CreatePlane(CntrPt,EndPl.Plane.Normal.AsVector)

Dim intPoints As ObjectsEnumerator
Dim intPoint As Point
Dim Jndx As Long
Dim foundEnts As ObjectsEnumerator
Dim locPoints As ObjectsEnumerator
Dim resultPoints As ObjectCollection

resultPoints = ThisApplication.TransientObjects.CreateObjectCollection

''Jndx triggers start plane or end plane of the frame generator part, hopefully
For Jndx = 0 To 1
Dim skNormal As UnitVector
skNormal = IIf (Jndx<1, StrtPl.Plane.Normal, EndPl.Plane.Normal)
Dim proxVector As Object
Dim proxPoint As Object


Dim msg As String
msg = CntrPt.X & ", " & CntrPt.Y & ", " & CntrPt.Z & vbCrLf & StrtPl.Plane.Normal.X & ", " & StrtPl.Plane.Normal.Y & ", " & StrtPl.Plane.Normal.Z _
& vbCrLf & EndPl.Plane.Normal.X & ", " & EndPl.Plane.Normal.Y & ", " & EndPl.Plane.Normal.Z
MessageBox.Show(msg, "Title")
MessageBox.Show(PrtCmp.Document.displayname,"Using")

''added calls to get a proxy for the center point and vectors hoping to get to find something at the foundEnts below
'' get error parameter incorrect

Call ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.ItemByName(PrtCmp.Document.displayname).CreateGeometryProxy(CntrPt, proxPoint)
Call ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.ItemByName(PrtCmp.Document.displayname).CreateGeometryProxy(skNormal, proxVector)

Dim TrgtFound As ObjectsEnumerator = ThisApplication.ActiveDocument.ComponentDefinition.FindUsingVector(proxPoint, _
proxVector, {SelectionFilterEnum.kAllEntitiesFilter })

 

' Call PrtCmp.FindUsingRay(CntrPt, IIf(Jndx=0,StrtPl,EndPl), 0.01, TrgtFound, locPoints, False)

For Indx = 1 To oAxis.Keys.Count

intPoints = oAxis.Item(Indx).line.IntersectWithSurface(IIf (Jndx<1, repStrt, repEnd))

intPoint = intPoints(1)
MessageBox.Show(trgtfound.Count, "Title")
Call trgtfound(1).definition.FindUsingRay(intPoint, skNormal, 0.00001, foundEnts, locPoints, True)

'' tried different things with different errors, as is, the error is that nothing was found.

' If an intersection was found, add it to the list.
MessageBox.Show("Message", "Title")
If locPoints.Count > 0 Then

''If foundEnts(1).type = ObjectTypeEnum.kFaceProxyObject Then
Dim wp As WorkPoint = trgtfound(1).definition.workpoints.addfixed(locpoints(1))

wp.Name = "WP_" & Left(PrtCmp.Document.fullfilename,Len(PrtCmp.Document.fullfilename)-4) & Indx
''End If
End If


Next 'Indx
Next 'Jndx


End Sub

Sub GetAxes(ByVal PrtComp As Inventor.PartComponentDefinition, ByRef oAxis As Dictionary(Of Object, Object))

Dim oAxs As Inventor.WorkAxis
Dim Indx As Long

If PrtComp.WorkAxes.Count >3 Then
Indx = 0

For Each oAxs In PrtComp.WorkAxes
If oAxs.IsCoordinateSystemElement = False Then
Indx = Indx + 1
oAxis.ADD(Indx, oAxs)
End If
Next

End If

End Sub

<\code>

0 Likes
426 Views
3 Replies
Replies (3)
Message 2 of 4

dhanna
Enthusiast
Enthusiast

I changed the subroutine call to recieve the componentoccurrence instead of the surfacebody so that it would be easier to call the oOcc.CreateGeometryProxy and still get an error
on the parameter(s) both calls fail.

 

Error in rule: Assembly_CreateHolesFromHorizontals, in document: HoleTransfer Experiment.iam

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.ComponentOccurrence.CreateGeometryProxy(Object Geometry, Object& Result)
at ThisRule.CreateHoles(ComponentOccurrence oOcc)
at ThisRule.TraverseAssembly(ComponentOccurrences& oOccs)
at ThisRule.TraverseAssembly(ComponentOccurrences& oOccs)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

<code>
Sub Main
' Get the active assembly.
Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument

'On Error Resume Next
'MessageBox.Show(oAssyDoc.FullDocumentName, "Title")
Call TraverseAssembly(oAssyDoc.ComponentDefinition.Occurrences)

End Sub

Sub TraverseAssembly(ByRef oOccs As ComponentOccurrences)
' Iterate through all of the occurrence in this collection
Dim oOcc As ComponentOccurrence

' On Error Resume Next

For Each oOcc In oOccs

If oOcc.DefinitionDocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
'' Recursively Call Sub If needed

Call TraverseAssembly(oOcc.SubOccurrences)
Else If oOcc.Definition.Document.propertysets.item("Design Tracking Properties").item("Stock Number").VALUE = "846IBG178" Then
'oOcc.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject And oOcc.SurfaceBodies.Count >0 Then
CreateHoles(oOcc)      '<<<<<<<<<<<<<<<<<<<<<changed this to pass the occurrence instead of surfacebody
End If

Next

End Sub

Sub CreateHoles(ByVal oOcc As Inventor.ComponentOccurrence)   ''<<<<<<<<<<<<changed to receive occurrence

Dim SrfcBd As Inventor.SurfaceBody = oOcc.Definition.SurfaceBodies(1)
Dim PrtCmp As Inventor.PartComponentDefinition

PrtCmp = SrfcBd.Parent

Dim oAxis As Dictionary(Of Object, Object)
Dim oAxs As Inventor.WorkAxis
Dim oNrml As Inventor.UnitVector
Dim oNrmlRev As Inventor.UnitVector
Dim ZLength As Double
Dim sktch As PlanarSketch
Dim oPln As Object
Dim CNTRD As Object
Dim EndFc As Inventor.Face
Dim StrtFc As Inventor.Face
Dim oTG As TransientGeometry
Dim Indx As Long
Dim CntrPt As Inventor.Point= PrtCmp.MassProperties.CenterOfMass

oTG = ThisApplication.TransientGeometry

oAxis = New Dictionary(Of Object, Object)

Call GetAxes(PrtCmp, oAxis)

sktch = PrtCmp.Features.ExtrudeFeatures(1).Definition.Profile(1)(1).SketchEntity.Parent
oPln = sktch.PlanarEntity

EndFc = PrtCmp.Features.ExtrudeFeatures(1).Faces.Item(PrtCmp.Features.ExtrudeFeatures(1).Faces.Count)
StrtFc = PrtCmp.Features.ExtrudeFeatures(1).Faces.Item(PrtCmp.Features.ExtrudeFeatures(1).Faces.Count - 1)

Dim repStrt As Inventor.Plane
Dim repEnd As Inventor.Plane

Dim EndPl = PrtCmp.WorkPlanes("End Plane")
Dim StrtPl = PrtCmp.WorkPlanes("Start Plane")

repStrt = oTG.CreatePlane(CntrPt,StrtPl.Plane.Normal.AsVector)
repEnd = oTG.CreatePlane(CntrPt,EndPl.Plane.Normal.AsVector)

Dim intPoints As ObjectsEnumerator
Dim intPoint As Point
Dim Jndx As Long
Dim foundEnts As ObjectsEnumerator
Dim locPoints As ObjectsEnumerator
Dim resultPoints As ObjectCollection

resultPoints = ThisApplication.TransientObjects.CreateObjectCollection

''Jndx triggers start plane or end plane of the frame generator part, hopefully
For Jndx = 0 To 1
Dim skNormal As UnitVector
skNormal = IIf (Jndx<1, StrtPl.Plane.Normal, EndPl.Plane.Normal)
Dim proxVector As Object
Dim proxPoint As Object


'Dim msg As String
' msg = CntrPt.X & ", " & CntrPt.Y & ", " & CntrPt.Z & vbCrLf & StrtPl.Plane.Normal.X & ", " & StrtPl.Plane.Normal.Y & ", " & StrtPl.Plane.Normal.Z _
' & vbCrLf & EndPl.Plane.Normal.X & ", " & EndPl.Plane.Normal.Y & ", " & EndPl.Plane.Normal.Z
'MessageBox.Show(msg, "Title")


''these calls both fail <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

 

Call oOcc.CreateGeometryProxy(EndPl.Plane.Normal, proxVector) 'oOcc.CreateGeometryProxy(skNormal, proxVector)
MessageBox.Show(oOcc.Definition.Document.displayname,"Using")
Call oOcc.CreateGeometryProxy(CntrPt, proxPoint) 'oOcc.CreateGeometryProxy(CntrPt, proxPoint)

MessageBox.Show(oOcc.Definition.Document.displayname,"Using")

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

'

Dim TrgtFound As ObjectsEnumerator = ThisApplication.ActiveDocument.ComponentDefinition.FindUsingVector(proxPoint, _
proxVector, {SelectionFilterEnum.kAllEntitiesFilter })

 

' Call PrtCmp.FindUsingRay(CntrPt, IIf(Jndx=0,StrtPl,EndPl), 0.01, TrgtFound, locPoints, False)

For Indx = 1 To oAxis.Keys.Count

intPoints = oAxis.Item(Indx).line.IntersectWithSurface(IIf (Jndx<1, repStrt, repEnd))

intPoint = intPoints(1)
MessageBox.Show(trgtfound.Count, "Title")
Call trgtfound(1).definition.FindUsingRay(intPoint, skNormal, 0.00001, foundEnts, locPoints, True)
' If an intersection was found, add it to the list.
MessageBox.Show("Message", "Title")
If locPoints.Count > 0 Then

''If foundEnts(1).type = ObjectTypeEnum.kFaceProxyObject Then
Dim wp As WorkPoint = trgtfound(1).definition.workpoints.addfixed(locpoints(1))

wp.Name = "WP_" & Left(PrtCmp.Document.fulldocumentname,Len(PrtCmp.Document.fullfilename)-4) & Indx
''End If
End If


Next 'Indx
Next 'Jndx


End Sub

Sub GetAxes(ByVal PrtComp As Inventor.PartComponentDefinition, ByRef oAxis As Dictionary(Of Object, Object))

Dim oAxs As Inventor.WorkAxis
Dim Indx As Long

If PrtComp.WorkAxes.Count >3 Then
Indx = 0

For Each oAxs In PrtComp.WorkAxes
If oAxs.IsCoordinateSystemElement = False Then
Indx = Indx + 1
oAxis.ADD(Indx, oAxs)
End If
Next

End If

End Sub


<\code>

0 Likes
Message 3 of 4

dhanna
Enthusiast
Enthusiast

I changed it up to see if I could get findusingvector or findusingray to work in the assembly with no success

<code>
Sub
Main ' Get the active assembly. Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument 'On Error Resume Next 'MessageBox.Show(oAssyDoc.FullDocumentName, "Title") Call TraverseAssembly(oAssyDoc.ComponentDefinition.Occurrences,oAssyDoc) End Sub Sub TraverseAssembly(ByRef oOccs As ComponentOccurrences, ByRef oAssyDoc As Object) ' Iterate through all of the occurrence in this collection Dim oOcc As ComponentOccurrence ' On Error Resume Next For Each oOcc In oOccs If oOcc.DefinitionDocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then '' Recursively Call Sub If needed Call TraverseAssembly(oOcc.SubOccurrences, oAssyDoc) Else If oOcc.Definition.Document.propertysets.item("Design Tracking Properties").item("Stock Number").VALUE = "846IBG178" Then 'oOcc.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject And oOcc.SurfaceBodies.Count >0 Then CreateHoles(oOcc,oAssyDoc) End If Next End Sub Sub CreateHoles(ByVal oOcc As Inventor.ComponentOccurrence, ByRef oAssyDoc As Object) Dim SrfcBd As Inventor.SurfaceBody = oOcc.Definition.SurfaceBodies(1) Dim PrtCmp As Inventor.PartComponentDefinition PrtCmp = SrfcBd.Parent Dim oAxis As Dictionary(Of Object, Object) Dim oAxs As Inventor.WorkAxis Dim oNrml As Inventor.UnitVector Dim oNrmlRev As Inventor.UnitVector Dim ZLength As Double Dim sktch As PlanarSketch Dim oPln As Object Dim CNTRD As Object Dim EndFc As Inventor.Face Dim StrtFc As Inventor.Face Dim oTG As TransientGeometry Dim Indx As Long Dim CntrPt As Inventor.Point= PrtCmp.MassProperties.CenterOfMass Dim repStrt As Inventor.Plane Dim repEnd As Inventor.Plane Dim EndPl = PrtCmp.WorkPlanes("End Plane") Dim StrtPl = PrtCmp.WorkPlanes("Start Plane") Dim intPoints As ObjectsEnumerator Dim intPoint As Point Dim Jndx As Long Dim foundEnts As ObjectsEnumerator Dim locPoints As ObjectsEnumerator Dim resultPoints As ObjectCollection Dim proxVector As Object Dim proxPoint As Object Dim skNormal As UnitVector oTG = ThisApplication.TransientGeometry oAxis = New Dictionary(Of Object, Object) Call GetAxes(PrtCmp, oAxis) ''Jndx triggers start plane or end plane of the frame generator part, hopefully For Jndx = 0 To 1 skNormal = IIf (Jndx<1, StrtPl.Plane.Normal, EndPl.Plane.Normal) 'Dim TrgtFound As ObjectsEnumerator = oAssyDoc.ComponentDefinition.FindUsingVector(CntrPt, _ ' skNormal, {SelectionFilterEnum.kAllEntitiesFilter }) ''<<<<< this gives zero objects returned '' Call oAssyDoc.ComponentDefinition.CreateGeometryProxy(CntrPt, proxPoint) '''<<< fails creategeometryproxy not a member '' Call oAssyDoc.ComponentDefinition.CreateGeometryProxy(skNormal, proxVector) '''<<< fails creategeometryproxy not a member ' Call oOcc.CreateGeometryProxy(CntrPt, proxPoint) '''<<< fails parameter "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))" ' Call oOcc.CreateGeometryProxy(skNormal, proxVector) '''<<< fails parameter "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))" 'Dim TrgtFound As ObjectsEnumerator = oAssyDoc.ComponentDefinition.FindUsingVector(proxPoint, _ ' proxVector, {SelectionFilterEnum.kAllEntitiesFilter }) ' MessageBox.Show(TrgtFound.Count, "TrgtFound") Dim TrgtFound As ObjectsEnumerator ' Call SrfcBd.FindUsingRay(CntrPt, skNormal, .1, TrgtFound, resultPoints, False) ' Call PrtCmp.FindUsingRay(CntrPt, skNormal, .1, TrgtFound, resultPoints, False) '' System.InvalidCastException : Unable To cast COM Object Of Type '' 'System.__ComObject' to interface type 'Inventor.ObjectCollection'. This operation '' failed because the QueryInterface Call On the COM Component For the Interface With '' IID '{6939FFDD-BA10-11D2-B779-0060B0F159EF}' failed due to the following error: '' No such Interface supported (Exception From HRESULT: 0x80004002 (E_NOINTERFACE)). '' at ThisRule.CreateHoles(ComponentOccurrence oOcc, Object& oAssyDoc) '' at ThisRule.TraverseAssembly(ComponentOccurrences& oOccs, Object& oAssyDoc) '' at ThisRule.TraverseAssembly(ComponentOccurrences& oOccs, Object& oAssyDoc) '' at ThisRule.Main() '' at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem) '' at iLogic.RuleEvalContainer.ExecRuleEval(String execRule) Call oOcc.Definition.FindUsingRay(CntrPt, skNormal, .1, TrgtFound, resultPoints, False) 'System.Runtime.InteropServices.COMException (0x80020005): Type mismatch. (Exception From HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH)) ' at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn) ' at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object [] Arguments, String [] ArgumentNames, Type [] ' TypeArguments, Boolean [] CopyBack, Boolean IgnoreReturn) ' at ThisRule.CreateHoles(ComponentOccurrence oOcc, Object& oAssyDoc) ' at ThisRule.TraverseAssembly(ComponentOccurrences& oOccs, Object& oAssyDoc) ' at ThisRule.TraverseAssembly(ComponentOccurrences& oOccs, Object& oAssyDoc) ' at ThisRule.Main() ' at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem) ' at iLogic.RuleEvalContainer.ExecRuleEval(String execRule) MessageBox.Show(TrgtFound.Count, "TrgtFound") Next 'Jndx End Sub Sub GetAxes(ByVal PrtComp As Inventor.PartComponentDefinition, ByRef oAxis As Dictionary(Of Object, Object)) Dim oAxs As Inventor.WorkAxis Dim Indx As Long If PrtComp.WorkAxes.Count >3 Then Indx = 0 For Each oAxs In PrtComp.WorkAxes If oAxs.IsCoordinateSystemElement = False Then Indx = Indx + 1 oAxis.ADD(Indx, oAxs) End If Next End If End Sub <\code>

 

0 Likes
Message 4 of 4

dhanna
Enthusiast
Enthusiast

I have managed to get the vector of the parts extrude direction in terms of the asssembly through the create geometry proxy, however when I try to get the origin of the part in terms of the assembly, using surfacebodyproxy.componentdefinition.workpoints(1), or center of mass in the same approach surfacebodyproxy.componentdefinition.massproperties.centerofmass (sorry if it should be .definition, I'm  typing this from memory- away from my rig) it gives me the point from the part not the assembly. 

I had expected calling the surfacebodyproxy it would return the proxy of points and axes, instead it returns the part's point or axis. 

I thought I had fixed it when I managed to get the vector 'proxy', but the findusingvector returned 0 items, so I dug in deeper and discovered that the start point at each horizontal was the same because it was returning the point as it is in the part not the assembly.

0 Likes