How to create wall assembly with selected parts on inventor with VB.net code.

How to create wall assembly with selected parts on inventor with VB.net code.

ganesh.rajapurkar-ext
Contributor Contributor
1,602 Views
28 Replies
Message 1 of 29

How to create wall assembly with selected parts on inventor with VB.net code.

ganesh.rajapurkar-ext
Contributor
Contributor

Hi Team,

 

I want to create assembly through VB .net code with 5 parts files .

And its actual output should look like Picture(Final outputPart-1Part-1Part-3Part-3Part-2Part-2Part-4Part-4Part-5Part-5Final Output.PNG

0 Likes
Accepted solutions (1)
1,603 Views
28 Replies
Replies (28)
Message 2 of 29

Michael.Navara
Advisor
Advisor
0 Likes
Message 3 of 29

ganesh.rajapurkar-ext
Contributor
Contributor

1]I want to add First part on inventor assembly as grounded.

2]Second part should be added vertically to first grounded part.

3]Third part should be horizontally added to second part.

4]Fourth part should get added to third part and First part vertically.

5]Squre part should be added in th emiddle.

 

 

The final output should look like "Final Output.png"

 

 

0 Likes
Message 4 of 29

Michael.Navara
Advisor
Advisor

This forum is not free coding platform. You need to try something and members can help you to solve an issues.

Here is sample how to place component to the assembly. Assembly Add Occurrence API Sample

Look at this sample, try something and later on ask a question.

 

 

Message 5 of 29

ganesh.rajapurkar-ext
Contributor
Contributor

Actually we have written following code to add two parts and perform mate constrain on those but actual result is not coming.Following is the code we have written :

 

Private Sub MateConstraint()
Dim oAssyDoc As AssemblyDocument
oAssyDoc = inventorApp.ActiveDocument
Dim oOcc1 As ComponentOccurrence
Dim oOcc2 As ComponentOccurrence

oOcc1 = oAssyDoc.ComponentDefinition.Occurrences(1)
oOcc2 = oAssyDoc.ComponentDefinition.Occurrences(2)

Dim oPartDef1 As PartComponentDefinition
oPartDef1 = oOcc1.Definition

Dim oPartDef2 As PartComponentDefinition
oPartDef2 = oOcc2.Definition

Dim iMate1 As iMateDefinition
iMate1 = oPartDef1.iMateDefinitions.Item(1)
Dim iMate2 As iMateDefinition
iMate2 = oPartDef2.iMateDefinitions.Item(1)

Dim oEntity1 As Face
Dim oEntity2 As Face

Call oOcc1.CreateGeometryProxy(iMate1.Entity, oEntity1)
Call oOcc2.CreateGeometryProxy(iMate2.Entity, oEntity2)

Dim colCons As AssemblyConstraint
colCons = oAssyDoc.ComponentDefinition.Constraints.AddMateConstraint(oEntity1, oEntity2, 0)

End Sub

0 Likes
Message 6 of 29

Michael.Navara
Advisor
Advisor

I tested your code and it works as expected. Mate was created.

0 Likes
Message 7 of 29

ganesh.rajapurkar-ext
Contributor
Contributor

But before mating I have to position these parts one after another.

1] First Part I have to set as grounded.(which I can do programmatically)

2]Second part should be connected to first part edge in 90 degree.

3]And then perform mate constraint on edges of these two parts.

4]Third part should be connected with second part on its edges. Again it will form 90 degree angle.

    Horizontal placement of part.

5]Fourth part should be connected with third part and first part.

Point No. 2 to 5 are hurdles or us to create assembly which looks like Square.

Is there any I logic rule wriiten for automating such kind of assembly.Then it will be useful for us to get guidance.

 

 

 

0 Likes
Message 8 of 29

ganesh.rajapurkar-ext
Contributor
Contributor

Example.PNGI wants to create such kind of assembly by performing mate constrain on these two parts.

0 Likes
Message 9 of 29

ganesh.rajapurkar-ext
Contributor
Contributor

Private Sub MateConstraint()

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = inventorApp.ActiveDocument.ComponentDefinition

' Set a reference to the select set.
Dim oSelectSet As SelectSet
oSelectSet = inventorApp.ActiveDocument.SelectSet

'Dim oFace1 As Object = oSelectSet.Item(1)
'Dim oFace2 As Object = oSelectSet.Item(2)

'Dim oMate As MateConstraint
'oMate = oAsmCompDef.Constraints.AddMateConstraint(oFace1, oFace2, 0)

Dim face1 As Face
face1 = inventorApp.CommandManager.Pick(
SelectionFilterEnum.kPartFacePlanarFilter,
"Select planar face 1.")
Dim face2 As Face
face2 = inventorApp.CommandManager.Pick(
SelectionFilterEnum.kPartFacePlanarFilter,
"Select planar face 2.")

Dim mate As MateConstraint
mate = oAsmCompDef.Constraints.AddMateConstraint(face1, face2, 0)

End Sub

 

This is my code where I have passed the planner face selection but I dont want it .I want these two parts to be added with each other through mate programatically on exact faces. 

0 Likes
Message 10 of 29

ganesh.rajapurkar-ext
Contributor
Contributor

Can anyone help me out on this?

0 Likes
Message 11 of 29

ganesh.rajapurkar-ext
Contributor
Contributor

Any help on this would be highly appreciated.

 

0 Likes
Message 12 of 29

ganesh.rajapurkar-ext
Contributor
Contributor

Dim oAsm As AssemblyDocument = inventorApp.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAsm.ComponentDefinition

' create geometry proxy 1
Dim oOcc1 As ComponentOccurrence
oOcc1 = oAsmCompDef.Occurrences(1)
Dim oPartPlaneXZ As WorkPlane
oPartPlaneXZ = oOcc1.Definition.WorkPlanes(1)
Dim oPartPlane1 As WorkPlaneProxy = Nothing
oOcc1.CreateGeometryProxy(oPartPlaneXZ, oPartPlane1)

' create geometry proxy 2
Dim oOcc2 As ComponentOccurrence
oOcc2 = oAsmCompDef.Occurrences(2)
Dim oPart2PlaneXZ As WorkPlane
oPart2PlaneXZ = oOcc2.Definition.WorkPlanes(2)
Dim oPart2Plane1 As WorkPlaneProxy = Nothing
oOcc2.CreateGeometryProxy(oPart2PlaneXZ, oPart2Plane1)

' and finally add the constraint
oAsmCompDef.Constraints.AddMateConstraint(oPartPlane1, oPart2Plane1, 0)

 

I have written this code to perform mat eon two parts but its not giving exact output as attached image:

 

0 Likes
Message 13 of 29

ganesh.rajapurkar-ext
Contributor
Contributor

Can anybody help me to achieve this frame using VB.Net code 

0 Likes
Message 14 of 29

A.Acheson
Mentor
Mentor

A method you could use is to assemble manually the parts in the assembly. Use ilogic capture snippet to add the constraints. Then replicate these constraints using the API. You will then see where your constraints may be failing. 

 

Alternately just add the part constraints with ilogic only. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 15 of 29

ganesh.rajapurkar-ext
Contributor
Contributor

Thank You for this reply.

We are very new to Inventor and its programming too. Can you please let me know How to capture I logic snippet when we starts creating assembly manually?

 

Once I get to know this, I will try to implement this things in programmatic way.

0 Likes
Message 16 of 29

A.Acheson
Mentor
Mentor

If you right click the occurrence in the editor and select Capture Current State (Constraints.Add).

Help file here

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 17 of 29

ganesh.rajapurkar-ext
Contributor
Contributor

Thanks for your reply.I tried capturing event of constraint and adding parts.

But i am having issues when I convert following iLogic rule to VB.Net code

 

Component.IsActive("091Z004429-0043:1") = True
Dim _091Z004429_0043_1 = Components.Add("091Z004429-0043:1",
"091Z004429-0043.IPT")


Dim _091Z004429_0043_1Pos = ThisAssembly.Geometry.Matrix(0, -1, 0, 0,
1, 0, 0, 23.365932173314,
0, 0, 1, 0.567090292501,
0, 0, 0, 1)
Dim _091Z004429_0043_1 = Components.Add("091Z004429-0043:1",
"091Z004429-0043.IPT",
_091Z004429_0043_1Pos)

 

Can anybody let me know how to convert iLogic code to VBA or vb.Net

0 Likes
Message 18 of 29

ganesh.rajapurkar-ext
Contributor
Contributor

Can anybody let me know what is the equivalent VBA or VB.Net code for following iLogic command :

 

ThisAssembly.Geometry.Matrix
0 Likes
Message 19 of 29

A.Acheson
Mentor
Mentor

Here is the ilogic help file for object ThisAssembly.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 20 of 29

ganesh.rajapurkar-ext
Contributor
Contributor
Accepted solution

I wants to perform mate on two parts using edges of each part.

1st Part Edg-0

2nd Part Edge-3

 

I am trying to find out edged of each occurrence using below code but there is an exception thrown: Invalid Parameter.

 

Following is my code :

Dim oEdge1 As Edge = oOcc1.SurfaceBodies(0).Edges
Dim oEdge2 As Edge = oOcc1.SurfaceBodies(3).Edges
''Create a mate constraint
oAsm.Constraints.AddMateConstraint(oEdge1, oEdge2, InferredTypeEnum.kNoInference, InferredTypeEnum.kInferredPoint)

 

Can anybody help on this.

 

 

0 Likes