FaceProxy - Select Face from Assembly and Take the EdgeLoop

FaceProxy - Select Face from Assembly and Take the EdgeLoop

florian_wenzel
Advocate Advocate
4,047 Views
14 Replies
Message 1 of 15

FaceProxy - Select Face from Assembly and Take the EdgeLoop

florian_wenzel
Advocate
Advocate

Hi;

 

Invnentor 2022

API: VB.NET VisualStudio

 

i try to Select a Face in Assembly Enviroment,

then i want to take the Insides EdgeLoop.

And from every Inside EdgeLoop take the CenterPoint, Create WorkAxis, WorkPlane, PlanarSketch and Extrude Negative, CutOperation - Make Holes.

 

The Problem is that this is Face in Other Part in Other Assembly.

florian_wenzel_0-1655393339073.png

 

 

This is my Code:

 

 

 

 

 

Public Sub CommandFunctionfweButton_07()


		Dim oAsmDoc As AssemblyDocument = g_inventorApplication.ActiveDocument
		Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
		Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
		Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry

		'Create Matrix
		Dim oMatrix As Matrix
		oMatrix = oTG.CreateMatrix


		'Create New Part in Main Assembly
		Dim oNameFile As String = InputBox("text")
		Dim oPartB As PartDocument = g_inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject)
		oPartB.SaveAs("C:\InventorAPI\1780-007\Part_B_" & oNameFile & ".ipt", False)


		'Create NewOccurrence, PartComponentDefinition
		Dim oOccPartB As ComponentOccurrence
		oOccPartB = oAsmCompDef.Occurrences.AddByComponentDefinition(oPartB.ComponentDefinition, oMatrix)
		oPartB.Close()

		Dim oPartB_Def As PartComponentDefinition = oOccPartB.Definition


		'Create New Sketch and Profile and Extrude
		Dim oSketchPartB As PlanarSketch = oPartB_Def.Sketches.Add(oPartB_Def.WorkPlanes.Item(3), False)

		Dim oRectangleLines As SketchEntitiesEnumerator
		oRectangleLines = oSketchPartB.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(40, 40))


		Dim oProfile As Profile
		oProfile = oSketchPartB.Profiles.AddForSolid

		Dim oExtrudeDef As ExtrudeDefinition
		oExtrudeDef = oPartB_Def.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation)
		Call oExtrudeDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kPositiveExtentDirection)
		Dim oExtrude1 As ExtrudeFeature
		oExtrude1 = oPartB_Def.Features.ExtrudeFeatures.Add(oExtrudeDef)


		'Select face form Other part in Other Assembly
		Dim oFace As Face = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face")

		Dim oOcc1 As ComponentOccurrence = oFace.Parent.Parent

		'Create faceProxy
		Dim oFaceProxy As FaceProxy
		Call oOcc1.CreateGeometryProxy(oFace, oFaceProxy)




		'Create Loop and Select every InsideEdgeLoop, create a CenterPoint, Axis, Plane, Sketch, Circle and Extrude.
		If oFace IsNot Nothing Then
			For Each oEdgeloop As EdgeLoop In oFace.EdgeLoops
				If Not oEdgeloop.IsOuterEdgeLoop Then
					Dim oEdgeColl As EdgeCollection = oTO.CreateEdgeCollection
					For Each oEdge In oEdgeloop.Edges
						oEdgeColl.Add(oEdge)

					Next

					Dim oWorkpoint As WorkPoint = oPartB_Def.WorkPoints.AddAtCentroid(oEdgeColl)

					Dim oWorkAxis As WorkAxis = oPartB_Def.WorkAxes.AddByNormalToSurface(oFace, oWorkpoint, False)

					Dim oWorkPlane As WorkPlane = oPartB_Def.WorkPlanes.AddByNormalToCurve(oWorkAxis, oWorkpoint, False)

					Dim oWorkSketch As PlanarSketch = oPartB_Def.Sketches.AddWithOrientation(oWorkPlane, oWorkAxis, True, True, oWorkpoint, True)

					Dim oPointCenters As SketchPoint
					oPointCenters = oWorkSketch.SketchPoints.Add(oTG.CreatePoint2d(0, 0), True)

					Dim oCircle As SketchCircle
					oCircle = oWorkSketch.SketchCircles.AddByCenterRadius(oPointCenters, 2)


					Dim oProfile01 As Profile
					oProfile01 = oWorkSketch.Profiles.AddForSolid

					Dim oExtrudeDef02 As ExtrudeDefinition
					oExtrudeDef02 = oPartB_Def.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile01, PartFeatureOperationEnum.kCutOperation)
					Call oExtrudeDef02.SetThroughAllExtent(PartFeatureExtentDirectionEnum.kSymmetricExtentDirection)
					Dim oExtrude2 As ExtrudeFeature
					oExtrude2 = oPartB_Def.Features.ExtrudeFeatures.Add(oExtrudeDef02)

				End If
			Next
		End If




	End Sub

 

 

Error:

Unknow Error

florian_wenzel_0-1655133436601.png

 

What i need to do with Proxy?

FaceProxy

EdgeLoopProxy

etc..

 

Thanks For Any Suggestion

0 Likes
4,048 Views
14 Replies
Replies (14)
Message 2 of 15

florian_wenzel
Advocate
Advocate

Hi,

i would be very grateful, if Someone could tell me:

What are the Rules, when i want to take Geometry (Face) from other Assembly?

and then use for example the Inside EdgeLoop to Create a CenterPoint of Each EdgeLoop.

 

I know, that when i what for Example Project a Curve from One Assembly to other Assembly, then i Create for Each Sketch a Proxy, and The Proxy need to be at the same Level.

 

But what i need to do with Face or FaceProxy.

How to use the Geometry in other Assembly, in other Part?

 

Is this Possible in API?

MjDeck

CGBenner

adam.nagy 

AlexKorzun

0 Likes
Message 3 of 15

florian_wenzel
Advocate
Advocate

Hi Again.

 

i have still Question about Taking Geometry from Face in Assembly Enviroment.

 

When i Pick a Face in Assembly Context, than this should be a Face or FaceProxy:

 

 

Dim oFace As Face = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face")

 

or

 

Dim oFace As FaceProxy = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face")

 

What are the Rules?

 

Then for EdgeLoop, i use the Face or FaceProxy ?

Or Face.NativeObject ?

 

From a FaceProxy when i want to take the EdgeLoop, i will Create EdgeLoop or EdgeLoopProxy?

 

In HelpDesk are info, that i Create From FaceProxy a normal EdgeLoop.

Inventor 2022 Help | FaceProxy.EdgeLoops Property | Autodesk

 

Than the Question, when i Create a EdgeLoopProxy ??? when from a FaceProxy i Create a Normal EdgeLoop?

 

If i want Create in a my PartB:  WorkPoint, WorkAxis and so on.

Then i Need to Create Proxy for Everything?

FaceProxy -- EdgeLoopProxy --EdgeProxy etc... ?

 

Is this Possible in Inventor API?

MjDeck

CGBenner

adam.nagy 

AlexKorzun

 

 

 

 

 

0 Likes
Message 4 of 15

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @florian_wenzel 

I did some experimenting with the files you sent me last week, and my recommendation is to just copy the surface with the holes as a nonparametricbasefeature, then handle everything else within the part.

To quickly test the code I wrote it as an iLogic rule. In the example you sent me, you can run it after PartA is created and first select the curved surface in Assembly_Elements, then the surface to copy the holes to in PartA 🙂

 

In the example files attached here, just pick the surface with the holes first and then a surface parallel to that surface in your other part.

I hope this helps! 🙂

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oTransaction As Transaction = ThisApplication.TransactionManager.StartTransaction(oAsm, "Create slots")
Dim oFace As FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face with original holes")
Dim oFaceOcc As ComponentOccurrence = oFace.ContainingOccurrence
Dim aFace As FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face to create holes on")
Dim aFaceRefKey(-1) As Byte
Dim aFaceKeyContext As Integer = oAsm.ReferenceKeyManager.CreateKeyContext
aFace.GetReferenceKey(aFaceRefKey, aFaceKeyContext)
Dim aOcc As ComponentOccurrence = aFace.ContainingOccurrence
Dim aDef As PartComponentDefinition = aOcc.Definition
Dim NPBFdef As NonParametricBaseFeatureDefinition = aDef.Features.NonParametricBaseFeatures.CreateDefinition
Dim oCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oCol.Add(oFace)
NPBFdef.BRepEntities = oCol
NPBFdef.OutputType = kSurfaceOutputType
NPBFdef.TargetOccurrence = aOcc
NPBFdef.IsAssociative = True

Dim planeInput As New List(Of KeyValuePair(Of WorkPoint, WorkAxis))

Dim cpySurf As NonParametricBaseFeature
cpySurf = aDef.Features.NonParametricBaseFeatures.AddByDefinition(NPBFdef)
For Each oLoop As EdgeLoop In cpySurf.Faces(1).EdgeLoops
	If oLoop.IsOuterEdgeLoop = False
		Dim oPoint As WorkPoint = aDef.WorkPoints.AddAtCentroid(oLoop)
		Dim oAxis As WorkAxis = aDef.WorkAxes.AddByNormalToSurface(oAsm.ReferenceKeyManager.BindKeyToObject(aFaceRefKey, aFaceKeyContext).NativeObject, oPoint)
		planeInput.Add(New KeyValuePair(Of WorkPoint, WorkAxis)(oPoint, oAxis))
	End If
Next
cpySurf.SurfaceBodies(1).Visible = False
For Each oPair As KeyValuePair(Of WorkPoint, WorkAxis) In planeInput
	Dim oPlane As WorkPlane = aDef.WorkPlanes.AddByNormalToCurve(oPair.Value, oPair.Key)
	Dim oSketch As PlanarSketch = aDef.Sketches.Add(oPlane)
	Dim oCP As SketchPoint = oSketch.AddByProjectingEntity(oPair.Key)
	Dim oEP As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oCP.Geometry.X + 1.5 / 2, oCP.Geometry.Y)
	Dim oSlot As SketchEntitiesEnumerator = oSketch.AddStraightSlotBySlotCenter(oCP, oEP, 0.8)
	Dim oLine As SketchLine = oSlot.OfType(Of SketchLine).FirstOrDefault(Function(x As SketchLine) x.Construction = True)
	oSketch.GeometricConstraints.AddHorizontal(oLine)
	oSketch.DimensionConstraints.AddTwoPointDistance(oLine.StartSketchPoint, oLine.EndSketchPoint, DimensionOrientationEnum.kHorizontalDim, oCP.Geometry)
	Dim oLines = oSlot.OfType(Of SketchLine).Where(Function(x As SketchLine) x.Construction = False)
	Dim oLine1 As SketchLine = oLines(0)
	Dim oLine2 As SketchLine = oLines(1)
	oSketch.DimensionConstraints.AddOffset(oLine1, oLine2, oCP.Geometry, False)
	Dim oProfile As Profile = oSketch.Profiles.AddForSolid
	aDef.Features.EmbossFeatures.AddEngraveFromFace(oProfile, 2, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, , oAsm.ReferenceKeyManager.BindKeyToObject(aFaceRefKey, aFaceKeyContext).NativeObject)
	oSketch.Visible = False
	oPlane.Visible = False
	oPair.Key.Visible = False
	oPair.Value.Visible = False
Next
oAsm.Update
oTransaction.End
Message 5 of 15

florian_wenzel
Advocate
Advocate

Hi @JhoelForshav 

 

Thanks.

Yes it works with the PartA.

Now i need to Translate this to VB.NET

I think is Possible.

 

 

 

 

 

I see this is more complicated than I thought.

My idea was with FaceProxy and EdgeLoop.

 

Thanks for the Solution!

 

 

0 Likes
Message 6 of 15

JhoelForshav
Mentor
Mentor
Accepted solution

@florian_wenzel 

It seems like using proxys as the geometry to add workgeometry doesn't work. For example using a proxy as the argument for a method like WorkPoints.AddAtCentroid will give an error.

 

iLogic is based on VB.NET so there isn't really anything to translate. Just replace ThisApplication with your Application object (g_inventorApplication) and replace ThisDoc.Document with g_inventorApplication.ActiveDocument and you're all set 🙂

 

Dim oAsm As AssemblyDocument = g_inventorApplication.ActiveDocument
Dim oTransaction As Transaction = g_inventorApplication.TransactionManager.StartTransaction(oAsm, "Create slots")
Dim oFace As FaceProxy = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face with original holes")
Dim oFaceOcc As ComponentOccurrence = oFace.ContainingOccurrence
Dim aFace As FaceProxy = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face to create holes on")
Dim aFaceRefKey(-1) As Byte
Dim aFaceKeyContext As Integer = oAsm.ReferenceKeyManager.CreateKeyContext
aFace.GetReferenceKey(aFaceRefKey, aFaceKeyContext)
Dim aOcc As ComponentOccurrence = aFace.ContainingOccurrence
Dim aDef As PartComponentDefinition = aOcc.Definition
Dim NPBFdef As NonParametricBaseFeatureDefinition = aDef.Features.NonParametricBaseFeatures.CreateDefinition
Dim oCol As ObjectCollection = g_inventorApplication.TransientObjects.CreateObjectCollection
oCol.Add(oFace)
NPBFdef.BRepEntities = oCol
NPBFdef.OutputType = kSurfaceOutputType
NPBFdef.TargetOccurrence = aOcc
NPBFdef.IsAssociative = True

Dim planeInput As New List(Of KeyValuePair(Of WorkPoint, WorkAxis))

Dim cpySurf As NonParametricBaseFeature
cpySurf = aDef.Features.NonParametricBaseFeatures.AddByDefinition(NPBFdef)
For Each oLoop As EdgeLoop In cpySurf.Faces(1).EdgeLoops
	If oLoop.IsOuterEdgeLoop = False
		Dim oPoint As WorkPoint = aDef.WorkPoints.AddAtCentroid(oLoop)
		Dim oAxis As WorkAxis = aDef.WorkAxes.AddByNormalToSurface(oAsm.ReferenceKeyManager.BindKeyToObject(aFaceRefKey, aFaceKeyContext).NativeObject, oPoint)
		planeInput.Add(New KeyValuePair(Of WorkPoint, WorkAxis)(oPoint, oAxis))
	End If
Next
cpySurf.SurfaceBodies(1).Visible = False
For Each oPair As KeyValuePair(Of WorkPoint, WorkAxis) In planeInput
	Dim oPlane As WorkPlane = aDef.WorkPlanes.AddByNormalToCurve(oPair.Value, oPair.Key)
	Dim oSketch As PlanarSketch = aDef.Sketches.Add(oPlane)
	Dim oCP As SketchPoint = oSketch.AddByProjectingEntity(oPair.Key)
	Dim oEP As Point2d = g_inventorApplication.TransientGeometry.CreatePoint2d(oCP.Geometry.X + 1.5 / 2, oCP.Geometry.Y)
	Dim oSlot As SketchEntitiesEnumerator = oSketch.AddStraightSlotBySlotCenter(oCP, oEP, 0.8)
	Dim oLine As SketchLine = oSlot.OfType(Of SketchLine).FirstOrDefault(Function(x As SketchLine) x.Construction = True)
	oSketch.GeometricConstraints.AddHorizontal(oLine)
	oSketch.DimensionConstraints.AddTwoPointDistance(oLine.StartSketchPoint, oLine.EndSketchPoint, DimensionOrientationEnum.kHorizontalDim, oCP.Geometry)
	Dim oLines = oSlot.OfType(Of SketchLine).Where(Function(x As SketchLine) x.Construction = False)
	Dim oLine1 As SketchLine = oLines(0)
	Dim oLine2 As SketchLine = oLines(1)
	oSketch.DimensionConstraints.AddOffset(oLine1, oLine2, oCP.Geometry, False)
	Dim oProfile As Profile = oSketch.Profiles.AddForSolid
	aDef.Features.EmbossFeatures.AddEngraveFromFace(oProfile, 2, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, , oAsm.ReferenceKeyManager.BindKeyToObject(aFaceRefKey, aFaceKeyContext).NativeObject)
	oSketch.Visible = False
	oPlane.Visible = False
	oPair.Key.Visible = False
	oPair.Value.Visible = False
Next
oAsm.Update
oTransaction.End

 

Message 7 of 15

florian_wenzel
Advocate
Advocate

Thanks @JhoelForshav 

dont know with:

153   kSurfaceOutputType 

Error: kSurfaceOutputType  not Declare

NPBFdef.OutputType = kSurfaceOutputType = Nothing ?? - Not Working also

 

158  Dim planeInput As New List(Of KeyValuePair(Of WorkPoint, WorkAxis)) 

Error: not define Variable and List

I need to write: Dim KeyValuePair As String ?

florian_wenzel_1-1655730411984.png

0 Likes
Message 8 of 15

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @florian_wenzel 

When it comes to kSurfaceOutputType, change it to BaseFeatureOutputTypeEnum.kSurfaceOutputType.

I think you should have the reference already in your project, but maybe you need to add the namespace System.Collections.Generic for your List and KeyValuePair. So either add Imports System.Collections.Generic at the top of your class or just add the namespace to your declarations:

Ex: Dim planeInput As New System.Collections.Generic.List(Of System.Collections.Generic.KeyValuePair(Of WorkPoint, WorkAxis))

 

See if this code works for you:

Dim oAsm As AssemblyDocument = g_inventorApplication.ActiveDocument
		Dim oTransaction As Transaction = g_inventorApplication.TransactionManager.StartTransaction(oAsm, "Create slots")
		Dim oFace As FaceProxy = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face with original holes")
		Dim oFaceOcc As ComponentOccurrence = oFace.ContainingOccurrence
		Dim aFace As FaceProxy = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face to create holes on")
		Dim aFaceRefKey(-1) As Byte
		Dim aFaceKeyContext As Integer = oAsm.ReferenceKeyManager.CreateKeyContext
		aFace.GetReferenceKey(aFaceRefKey, aFaceKeyContext)
		Dim aOcc As ComponentOccurrence = aFace.ContainingOccurrence
		Dim aDef As PartComponentDefinition = aOcc.Definition
		Dim NPBFdef As NonParametricBaseFeatureDefinition = aDef.Features.NonParametricBaseFeatures.CreateDefinition
		Dim oCol As ObjectCollection = g_inventorApplication.TransientObjects.CreateObjectCollection
		oCol.Add(oFace)
		NPBFdef.BRepEntities = oCol
		NPBFdef.OutputType = BaseFeatureOutputTypeEnum.kSurfaceOutputType
		NPBFdef.TargetOccurrence = aOcc
		NPBFdef.IsAssociative = True

		Dim planeInput As New System.Collections.Generic.List(Of System.Collections.Generic.KeyValuePair(Of WorkPoint, WorkAxis))



		Dim cpySurf As NonParametricBaseFeature
		cpySurf = aDef.Features.NonParametricBaseFeatures.AddByDefinition(NPBFdef)
		For Each oLoop As EdgeLoop In cpySurf.Faces(1).EdgeLoops
			If oLoop.IsOuterEdgeLoop = False Then
				Dim oPoint As WorkPoint = aDef.WorkPoints.AddAtCentroid(oLoop)
				Dim oAxis As WorkAxis = aDef.WorkAxes.AddByNormalToSurface(oAsm.ReferenceKeyManager.BindKeyToObject(aFaceRefKey, aFaceKeyContext).NativeObject, oPoint)
				planeInput.Add(New System.Collections.Generic.KeyValuePair(Of WorkPoint, WorkAxis)(oPoint, oAxis))
			End If
		Next
		cpySurf.SurfaceBodies(1).Visible = False
		For Each oPair As System.Collections.Generic.KeyValuePair(Of WorkPoint, WorkAxis) In planeInput
			Dim oPlane As WorkPlane = aDef.WorkPlanes.AddByNormalToCurve(oPair.Value, oPair.Key)
			Dim oSketch As PlanarSketch = aDef.Sketches.Add(oPlane)
			Dim oCP As SketchPoint = oSketch.AddByProjectingEntity(oPair.Key)
			Dim oEP As Point2d = g_inventorApplication.TransientGeometry.CreatePoint2d(oCP.Geometry.X + 1.5 / 2, oCP.Geometry.Y)
			Dim oSlot As SketchEntitiesEnumerator = oSketch.AddStraightSlotBySlotCenter(oCP, oEP, 0.8)
			Dim oLine As SketchLine = oSlot.OfType(Of SketchLine).FirstOrDefault(Function(x As SketchLine) x.Construction = True)
			oSketch.GeometricConstraints.AddHorizontal(oLine)
			oSketch.DimensionConstraints.AddTwoPointDistance(oLine.StartSketchPoint, oLine.EndSketchPoint, DimensionOrientationEnum.kHorizontalDim, oCP.Geometry)
			Dim oLines = oSlot.OfType(Of SketchLine).Where(Function(x As SketchLine) x.Construction = False)
			Dim oLine1 As SketchLine = oLines(0)
			Dim oLine2 As SketchLine = oLines(1)
			oSketch.DimensionConstraints.AddOffset(oLine1, oLine2, oCP.Geometry, False)
			Dim oProfile As Profile = oSketch.Profiles.AddForSolid
			aDef.Features.EmbossFeatures.AddEngraveFromFace(oProfile, 2, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, , oAsm.ReferenceKeyManager.BindKeyToObject(aFaceRefKey, aFaceKeyContext).NativeObject)
			oSketch.Visible = False
			oPlane.Visible = False
			oPair.Key.Visible = False
			oPair.Value.Visible = False
		Next
		oAsm.Update()
		oTransaction.End()
Message 9 of 15

florian_wenzel
Advocate
Advocate

Hi @JhoelForshav 

Still Error:

System.MissingMemberException: "Der öffentliche Member OfType für den Typ SketchEntitiesEnumerator wurde nicht gefunden."

System.MissingMemberException: "The public member OfType for the SketchEntitiesEnumerator type was not found."

 

florian_wenzel_0-1655733908478.png

 

0 Likes
Message 10 of 15

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @florian_wenzel 

Okay, so we'll probably need to import the System.Linq namespace aswell.

Add the line Imports System.Linq to the top of your class and see if that works 🙂

SystemLinq.png

Message 11 of 15

florian_wenzel
Advocate
Advocate

Hi @JhoelForshav 

 

It Works !

Thanks For help

Thanks for Solution!

Message 12 of 15

ROBOMACH_PL_1
Advocate
Advocate

Hi,

 

@JhoelForshav ,

 

I would like to modify your rule but I have a problem with that.

 

My point is exactly that:

 

1. I would like to be able to copy (pick) any number of surfaces with holes on one base surface.

 

2. I would like the result of this operation to be one sketch (now each projected hole is a new sketch and a new cut) with all the slots as it is now.

 

ralfmja_0-1663936325395.png

 

 

It seems to me that for a skilled programmer it is a small matter, but unfortunately I am a complete amateur. If point 1 would be a problem, I would be completely satisfied with solving the problem from point 2.

 

Would you be able to help me ??

 

Regards,

ralfmja

0 Likes
Message 13 of 15

ROBOMACH_PL_1
Advocate
Advocate

Hello All, hello @JhoelForshav 

 

I did a few tries and dealt with point 2 from my previous post. Now the code is as follows (probably not perfect, but it works):

sprawdzanie czy jesteśmy w złożeniu
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("REGULA DZIAŁA TYLKO W ZESPOLE", vbCritical, "OSTRZEŻENIE")
		Exit Sub
End If

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oTransaction As Transaction = ThisApplication.TransactionManager.StartTransaction(oAsm, "RZUTOWANIE OTWORÓW")
Dim oFace As FaceProxy
'obsluga bledu jezeli ktoś sie rozmysli przy wybieraniu plaszczyzny z otworami
While True
   oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "WSKAŻ PŁASZCZYZNE Z OTWORAMI")
	
	' jesli nic nie wybrane to	
	If IsNothing(oFace) Then Exit Sub Else
		Exit While
End While

Dim oFaceOcc As ComponentOccurrence = oFace.ContainingOccurrence

Dim aFace As FaceProxy

'obsluga bledu jezeli ktoś sie rozmysli przy wybieraniu plaszczyzny rzutowania
While True
   aFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "WSKAŻ PŁASZCZYZNE RZUTOWANIA")
	
	' jesli nic nie wybrane to 	
	If IsNothing(aFace) Then Exit Sub Else
		Exit While
End While

Dim aFaceRefKey(-1) As Byte
Dim aFaceKeyContext As Integer = oAsm.ReferenceKeyManager.CreateKeyContext
aFace.GetReferenceKey(aFaceRefKey, aFaceKeyContext)
Dim aOcc As ComponentOccurrence = aFace.ContainingOccurrence
Dim aDef As PartComponentDefinition = aOcc.Definition
Dim NPBFdef As NonParametricBaseFeatureDefinition = aDef.Features.NonParametricBaseFeatures.CreateDefinition
Dim oCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oCol.Add(oFace)
NPBFdef.BRepEntities = oCol
NPBFdef.OutputType = kSurfaceOutputType
NPBFdef.TargetOccurrence = aOcc
NPBFdef.IsAssociative = True

Dim planeInput As New List(Of KeyValuePair(Of WorkPoint, WorkAxis))

Dim cpySurf As NonParametricBaseFeature
cpySurf = aDef.Features.NonParametricBaseFeatures.AddByDefinition(NPBFdef)
For Each oLoop As EdgeLoop In cpySurf.Faces(1).EdgeLoops
	If oLoop.IsOuterEdgeLoop = False
		Dim oPoint As WorkPoint = aDef.WorkPoints.AddAtCentroid(oLoop)
		Dim oAxis As WorkAxis = aDef.WorkAxes.AddByNormalToSurface(oAsm.ReferenceKeyManager.BindKeyToObject(aFaceRefKey, aFaceKeyContext).NativeObject, oPoint)
		planeInput.Add(New KeyValuePair(Of WorkPoint, WorkAxis)(oPoint, oAxis))
	End If
Next
cpySurf.SurfaceBodies(1).Visible = False


    Dim oPlaszczyzna As WorkPlane = aDef.WorkPlanes.AddByPlaneAndOffset(oAsm.ReferenceKeyManager.BindKeyToObject(aFaceRefKey, aFaceKeyContext).NativeObject, 0)
	oPlaszczyzna.Visible = False
	Dim oSketch As PlanarSketch = aDef.Sketches.Add(oPlaszczyzna)
	oSketch.Visible = True
	
For Each oPair As KeyValuePair(Of WorkPoint, WorkAxis) In planeInput
	Dim oCP As SketchPoint = oSketch.AddByProjectingEntity(oPair.Key)
	Dim oEP As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oCP.Geometry.X + 1 / 2, oCP.Geometry.Y)
	Dim oSlot As SketchEntitiesEnumerator = oSketch.AddStraightSlotBySlotCenter(oCP, oEP, 0.9)
	Dim oLine As SketchLine = oSlot.OfType(Of SketchLine).FirstOrDefault(Function(x As SketchLine) x.Construction = True)
'	oSketch.GeometricConstraints.AddHorizontal(oLine)
	oSketch.DimensionConstraints.AddTwoPointDistance(oLine.StartSketchPoint, oLine.EndSketchPoint, DimensionOrientationEnum.kHorizontalDim, oCP.Geometry)
	Dim oLines = oSlot.OfType(Of SketchLine).Where(Function(x As SketchLine) x.Construction = False)
	Dim oLine1 As SketchLine = oLines(0)
	Dim oLine2 As SketchLine = oLines(1)
	oSketch.DimensionConstraints.AddOffset(oLine1, oLine2, oCP.Geometry, False)
'	Dim oProfile As Profile = oSketch.Profiles.AddForSolid
'	aDef.Features.EmbossFeatures.AddEngraveFromFace(oProfile, 2, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, , oAsm.ReferenceKeyManager.BindKeyToObject(aFaceRefKey, aFaceKeyContext).NativeObject)
	
	oSketch.DimensionsVisible=False
	oPair.Key.Visible = False
	oPair.Value.Visible = False
Next
oAsm.Update
oTransaction.End
InventorVb.DocumentUpdate() 

'Wyłaczenie adaptacyjnosci
iLogicVb.Automation.RunExternalRule(oAsm, "ADAPTACJA_OFF")

 

However, I am intrigued by point 1, i.e. how to add the possibility to choose several planes ??

I think I know what to do but I don't know how 😄

 

I would select several planes using the code:

Dim oSurfaces As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
While True
   oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "WSKAŻ PŁASZCZYZNE Z OTWORAMI")
	
	' jesli nic nie wybrane to	
	If IsNothing(oFace) Then GoTo wybor2 Else
	oSurfaces.Add(oFace)
End While

but I have no idea how to "stitch" these planes together so that the rest of the rule would be based on this stitching ??

 

Would anyone be able to help on this topic ??

 

Thanks in advance,

Best regard, 

ralfmja

0 Likes
Message 14 of 15

florian_wenzel
Advocate
Advocate

Hi,

 

dont know exactly what you need.

Dont understand me wrong, it is very good to try other code or example, but it will not always working how you want 🙂

 

The Origin Code, was made for Curved Surface, that why i needed the all Axis etc...

The Picture on the Begining was only a Simple Example.

 

On your Picture i see, you have a Planar Plane, so should be relative more simply, i think so.

Are all Parts with Planar Planes, Faces?

 

Try to describe more what you want, or show the Assembly tree, which Part in which assembly etc..

 

 

Suggestion:

When all Parts has Planar Faces, then my spotanic Suggestion is:

 

You need to have a Occurence from Part A and Part B

 

In Part A

Select a Face, or Select a Entity, than simply Create in Part A a PlanarSketch and SketchProxy

AddEntity to The Sketch in Part A.

 

In Part B

Create Sketch and SketchProxy

and simply Copy Content From Part A to PartB, for this you need Proxy.

 

I think this should work, when your Parts has PlanarFaces.

In my Case it was Curved Surfaces, that why was a little bit Tricky.

0 Likes
Message 15 of 15

ROBOMACH_PL_1
Advocate
Advocate
Accepted solution

Hi @florian_wenzel ,

 

thanks for you answer.

 

Yes - all planes with holes are flat and parallel to the plane on which it is projecting.

 

It is intended to be a "streamlined" tool for the adaptive projection of holes from different parts onto the one in which these holes are to be formed.

 

Inventor's standard approach to adaptability in large assemblies causes numerous problems with adaptability. For do this I use the "copy object" tool and then project that object onto the sketches and make the appropriate holes. The rule described in this topic allows you to significantly reduce the time required for these operations. However, it would be ideal for me if I could select and project all surfaces "at once".

But I never know how many planes I want to project (sometimes one, sometimes two, sometimes maybe 10 etc.).

 

Selecting planes seems to be done, but needs help in "joining" them and using them to project onto a selected plane.

 

I agree with you that it should be easier than with "rounded" surfaces, but I don't know how to do it anyway. 🙂

 

Thanks in advance,

Regards,

ralfmja