API for copy object of another part within assembly and then sculpt to surfaces

API for copy object of another part within assembly and then sculpt to surfaces

cencinaNB2ET
Advocate Advocate
1,445 Views
9 Replies
Message 1 of 10

API for copy object of another part within assembly and then sculpt to surfaces

cencinaNB2ET
Advocate
Advocate

Hi,

I want to see if there is a way to program Inventor to edit part in context of an assembly, create a copy of surface of another part and then sculpt the edit mode part to cut its body to that intersecting surface copy.

 

I found a sample code in the API help but its not exactly the same.

Just wondering if anyone has dealt with something similar before.

I attached a screen cast showing what i want the code to do automatically.

 

 

 

 

0 Likes
1,446 Views
9 Replies
Replies (9)
Message 2 of 10

cencinaNB2ET
Advocate
Advocate

Got the answer but I would like to know if there is a way to get the location of faces inside the part to create a faceproxy and use this code.

For now i just added an ilogic entity name to the part face and find the face number then get the actual face to create a faceproxy to use the code below.

 

any ideas??

 

 

Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim iLogicAuto As Object = iLogicVb.Automation
Dim Trim_To_oOcc As ComponentOccurrence 
Dim Trim_Occ As ComponentOccurrence
Dim Occurrences As ComponentOccurrences 
Dim WorkPlanes As WorkPlanes
Dim workPlane As WorkPlane
Dim oOriginPnt As Point
Dim oXaxis As UnitVector
Dim oYaxis As UnitVector
Dim oPart_1 As PartDocument
Dim oPart_2 As PartDocument
Dim oPart_Def_1 As PartComponentDefinition
Dim oPart_Def_2 As PartComponentDefinition
Dim oWrkPlane1Proxy As WorkPlaneProxy
Dim nonPrmFeatures As NonParametricBaseFeatures 
Dim featureDef As NonParametricBaseFeatureDefinition 
Dim transObjs As TransientObjects 
Dim col As ObjectCollection 
Dim baseFeature As NonParametricBaseFeature 
Dim oFeas As PartFeatures
Dim oSurfaces As ObjectCollection
Dim osurface As WorkSurface
Dim oSculpt As SculptFeature
Dim AttSets As AttributeSets
Dim AttSet As AttributeSet
Dim oFaces As Faces
Dim oFace As Face
Dim Found_Face As Face
Dim Extract_Item_Face As Integer
Dim Cut_To_Face_Name As String
Dim sourceFace As FaceProxy 



Trim_To_oOcc = oAsmDef.Occurrences.ItemByName("Obstacle Bridge Beam - 1.ipt:1")
Trim_Occ = oAsmDef.Occurrences.ItemByName("Obstacle Bridge Hoop - 1.ipt:1")
Cut_To_Face_Name = "Face0"



oPart_1 = Trim_To_oOcc.Definition.Document
oPart_2 = Trim_Occ.Definition.Document
oPart_Def_1 = Trim_To_oOcc.Definition
oPart_Def_2 = Trim_Occ.Definition



'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Method 1 - Gemetry ilogic Entity Names
For x = 1 To oPart_Def_1.SurfaceBodies(1).Faces.Count
oFace = oPart_Def_1.SurfaceBodies(1).Faces.Item(x)
AttSets = oFace.AttributeSets
If AttSets.NameIsUsed("iLogicEntityNameSet")  = True Then
	AttSet = AttSets.Item("iLogicEntityNameSet")
	For Each Att In AttSet
	If Att.Value = Cut_To_Face_Name Then
	Extract_Item_Face = x
	'MessageBox.Show("Edge Value: " & Att.Value & vbCr & E & vbCr &  Att.Name & x)
	iProperties.Value(Trim_To_oOcc.Name, "Custom", "Top Face Number") = Extract_Item_Face
'	sourceFace = oFace
	End If
	Next
End If
Next x
sourceFace = Trim_To_oOcc.SurfaceBodies(1).Faces(Extract_Item_Face)





'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Method 2 - Exisitng Workplane Name geometry match Face geometry??
'For Each oWorkplane As workPlane In oPart_Def_1.WorkPlanes
'If oWorkplane.Name = "Top Plane" Then
'Call Trim_To_oOcc.CreateGeometryProxy(oWorkplane, oWrkPlane1Proxy)
'Call oWrkPlane1Proxy.GetPosition(oOriginPnt, oXaxis, oYaxis)

'Exit For
'End If
'Next




nonPrmFeatures = oPart_Def_2.Features.NonParametricBaseFeatures 
featureDef = nonPrmFeatures.CreateDefinition  
transObjs = ThisApplication.TransientObjects  
col = transObjs.CreateObjectCollection 
col.Add(sourceFace)
featureDef.BRepEntities = col
featureDef.OutputType = kSurfaceOutputType
featureDef.TargetOccurrence = Trim_Occ 
featureDef.IsAssociative = True 
baseFeature = nonPrmFeatures.AddByDefinition(featureDef) 
oFeas = oPart_Def_2.Features
oSurfaces = ThisApplication.TransientObjects.CreateObjectCollection
For Each osurface In oPart_Def_2.WorkSurfaces
oSurfaces.Add(oFeas.SculptFeatures.CreateSculptSurface(osurface, kNegativeExtentDirection))
Next
oSculpt = oFeas.SculptFeatures.Add(oSurfaces, kCutOperation)




'EndCode:
iLogicVb.UpdateWhenDone = True







Message 3 of 10

Khoa_NguyenDang
Advocate
Advocate

Hi @cencinaNB2ET 

 

I found your code 

And it is right to copy object between parts in Assembly 

But it has some problem if I use that code in the Assembly with many SubAssembly 

If I want to copy a part from any subassembly to part in another subassembly. The Position of the part which is copied by code is not right. 

Can you help me to copy it with no change a position 

 

Thank you so much

0 Likes
Message 4 of 10

cencinaNB2ET
Advocate
Advocate

Well yes, I had a similar problem and thought was a bug because the surface copied would appear off target from the position of the part. Is you problem similar?

Message 5 of 10

Khoa_NguyenDang
Advocate
Advocate

Hi @cencinaNB2ET 

 

Thank for your reply

As the picture i attached when the code run, the bodies are copied's position is not same which the original position  

Hope you know this issue and have the solution for this

 

Thank you so much. 

Khoa_NguyenDang_0-1594346397353.png

 

0 Likes
Message 6 of 10

cencinaNB2ET
Advocate
Advocate

Yes its the same issue Autodesk needs to jump in here.

I had to figure a way to delete all surface-bodies, associativity, sculpts, etc... update the model, almost rebuild it every time i wanted to update the surface bodies locations for several files.

That code there is just one part of a bigger code sorting this out for me.

You can send the file here to have a better look but I believe its a bug. Ask Autodesk to confirm.

 

 

Message 7 of 10

Khoa_NguyenDang
Advocate
Advocate

HI @cencinaNB2ET

Thank so much for your reply 

Can I connect you by any method such as Skype, Facebook,....

So we can easy to discuss about thí problem 

Hope i can find the solution for my problem 

 

 

0 Likes
Message 8 of 10

cencinaNB2ET
Advocate
Advocate

Perhaps re-post it on Autodesk Forum first?

 

 

Message 9 of 10

Khoa_NguyenDang
Advocate
Advocate

Yes i also post it in Inventor Forum 

https://forums.autodesk.com/t5/inventor-customization/inventor-api-the-wrong-position-of-bodies-when...

Hope you can help me to find the solution 

0 Likes
Message 10 of 10

cencinaNB2ET
Advocate
Advocate

How did you go in the end with this problem? sorry I never saw this again, but I'm actually having a very similar problem with Inventor 2023 now.

0 Likes