Macro for Automating Assembly

Macro for Automating Assembly

Anonymous
Not applicable
1,530 Views
9 Replies
Message 1 of 10

Macro for Automating Assembly

Anonymous
Not applicable
Can we Make code for Selecting Part Automatically?
0 Likes
1,531 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
Hello mate,

The Inventor Developer's Help File contains samples for adding part files in to an assembly, including the code to mate relative to other parts. I would recommend you mate to planes, as I find these easier to locate within a part.

Jon
0 Likes
Message 3 of 10

Anonymous
Not applicable
Dear Jon,

Thanks for your reply.
I've gone thru the Sample files, the problem I'm facing here is for each program, we need to select the Part in the assembly before running macro, i want to make it auomated... As I'm following Standard part name, I can identify the part with their name, and insted of asking user to select the part, I want to select these part in run time... Can you help me in auomating the 'Selection' part? that will be a great help to novice like me.

With warm regards

Sumit
0 Likes
Message 4 of 10

ludesroc
Advocate
Advocate
Here is a brief exemple...Have an assy doc opened and run this code. The code will stop after selecting the first occurence in the browser. Press F5 the continue.

Sub SelectComponent()

Dim oAssy As AssemblyDocument
Set oAssy = ThisApplication.ActiveDocument

Dim oAssyCompDef As AssemblyComponentDefinition
Set oAssyCompDef = oAssy.ComponentDefinition

Dim oSelSet As SelectSet
Set oSelSet = ThisApplication.ActiveDocument.SelectSet

Dim oOcc As ComponentOccurrence
Set oOcc = oAssyCompDef.Occurrences.Item(1)

Call oSelSet.Select(oOcc)

' Do whatever here
'
'
Stop

oSelSet.Clear
Set oSelSet = Nothing

End Sub

Ludesroc.
Ludesroc
0 Likes
Message 5 of 10

Anonymous
Not applicable
Ehup mate,

Are you trying to add parts to an assembly, or identify them within an assembly? I'm a touch confused as to what you are aiming for? Edited by: jonbrabbs on Sep 17, 2009 12:51 PM
0 Likes
Message 6 of 10

Anonymous
Not applicable
Thank you Jonbrabbs,

Let me check this piece of code, if I have any doubt I'' trouble you again..
0 Likes
Message 7 of 10

Anonymous
Not applicable
Hello Dear,

I'm trying to add parts from pre-defined location, and the trying to constrain them.. basically I'm trying for 3 Cylindrical part with same Diameter but with different Material & Stock Number.

So I know How to add the part in assembly, but I'm not sure How to constrain them without asking user to select these parts.

as these are cylinder, we can very well constrain them with 'insert' & Plain constrain. Please help me in this regard
0 Likes
Message 8 of 10

ludesroc
Advocate
Advocate
I suggest you use iMate.

Look for...

1) Create an iMate --> Help Menu
2) iMate Using Entities -->Programming Help Menu Samples

Ludesroc
Ludesroc
0 Likes
Message 9 of 10

Anonymous
Not applicable
Ehup mate,

If you're putting the parts in using code, here is something I wrote in .NET to mate Planes and Axes

Sub AddAngleConstraint(ByVal EntityOne As Object, ByVal EntityTwo As Object, ByVal Offset As Double, ByVal strMateType As String, _
ByVal Axis1 As Integer, ByVal Axis2 As Integer)

On Error GoTo ErrH

oOcc1 = EntityOne
oOcc2 = EntityTwo
oPartAxis1 = oOcc1.Definition.workaxes.item(Axis1)
oPartAxis2 = oOcc2.Definition.workaxes.item(Axis2)
Call oOcc1.CreateGeometryProxy(oPartAxis1, oAsmAxis1)
Call oOcc2.CreateGeometryProxy(oPartAxis2, oAsmAxis2)

Select Case strMateType
Case "Flush"
Call oAsmCompDef.Constraints.AddFlushConstraint(oAsmAxis1, oAsmAxis2, Offset)
Case "Mate"
Call oAsmCompDef.Constraints.AddMateConstraint(oAsmAxis1, oAsmAxis2, Offset)
Case "Angle"
Call oAsmCompDef.Constraints.AddAngleConstraint(oAsmAxis1, oAsmAxis2, Offset)
Case "Special"
oPartPlane1 = oOcc1.Definition.workplanes.item(Axis1)
Call oOcc1.CreateGeometryProxy(oPartPlane1, oAsmPlane1)
Call oAsmCompDef.Constraints.AddMateConstraint(oAsmPlane1, oAsmAxis2, Offset)
End Select
ErrH:
End Sub

Public Sub AddMateConstraint(ByVal EntityOne As Object, ByVal EntityTwo As Object, ByVal Offset As Double, ByVal strMateType As String, _
ByVal Plane1 As Integer, ByVal Plane2 As Integer)
On Error Resume Next

oOcc1 = EntityOne
oOcc2 = EntityTwo
oPartPlane1 = oOcc1.Definition.workplanes.item(Plane1)
oPartPlane2 = oOcc2.Definition.workplanes.item(Plane2)
Call oOcc1.CreateGeometryProxy(oPartPlane1, oAsmPlane1)
Call oOcc2.CreateGeometryProxy(oPartPlane2, oAsmPlane2)

Select Case strMateType
Case "Flush"
Call oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane1, oAsmPlane2, Offset)
Case "Mate"
Call oAsmCompDef.Constraints.AddMateConstraint(oAsmPlane1, oAsmPlane2, Offset)
End Select

End Sub

These are called from the main sub by the following code

AddMateConstraint(BackPanel(c), BackPanel(c - 1), -0.45, "Flush", 1, 1)
AddMateConstraint(BackPanel(c), BackPanel(c - 1), (((-panelheight(i - 1)) / 10) / 2) + (((-panelheight(i)) / 10) / 2) - 1.3, "Flush", 2, 2)
AddMateConstraint(BackPanel(c), BackPanel(c - 1), 0, "Flush", 3, 3)

Where BackPanel(c) is component 1 and backpanel(c-1) is the second component.
BackPanel(c) = oOccs.AddiPartMember("S:\Design\Drawings\Library\Components\Gondola\Back Panel.ipt", oPos, iNumRows)

To add using iMAtes through code, you could use something like:

oOccEnumerator = oAsmCompDef.Occurrences.AddUsingiMates("S:\Design\Drawings\Library\Components\Gondola\Tek Fixing.ipt", True)

This will add parts to all available iMate locations (In this case 16 places). Changing to False, will add one occurrence in.

for you, it would look something like:

oOccEnumerator = oASmCompDef.Occurrences.AddUsingiMates("Cylinder.ipt", False)

Jon
Message 10 of 10

Anonymous
Not applicable

Hi, 

 

By ilogic - commandmanager, i would like to pick the part and use your function to make constraint.

 

SubMain()
EntityOne=ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter ,"Select Entities -1 to constraints:")
EntityTwo=ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter ,"Select Entities -2 to constraints:")
AddMateConstraint(EntityOne,EntityTwo, 0, "Flush", 3, 3)
End Sub

Sub AddAngleConstraint(ByVal EntityOne As Object, ByVal EntityTwo As Object, ByVal Offset As Double, ByVal strMateType As String, _
ByVal Axis1 As Integer, ByVal Axis2 As Integer)

On Error Goto ErrH
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
oOcc1 = EntityOne
oOcc2 = EntityTwo
oPartAxis1 = oOcc1.Definition.workaxes.item(Axis1)
oPartAxis2 = oOcc2.Definition.workaxes.item(Axis2)
Call oOcc1.CreateGeometryProxy(oPartAxis1, oAsmAxis1)
Call oOcc2.CreateGeometryProxy(oPartAxis2, oAsmAxis2)

Select Case strMateType
Case "Flush"
Call oAsmCompDef.Constraints.AddFlushConstraint(oAsmAxis1, oAsmAxis2, Offset)
Case "Mate"
Call oAsmCompDef.Constraints.AddMateConstraint(oAsmAxis1, oAsmAxis2, Offset)
Case "Angle"
Call oAsmCompDef.Constraints.AddAngleConstraint(oAsmAxis1, oAsmAxis2, Offset)
Case "Special"
oPartPlane1 = oOcc1.Definition.workplanes.item(Axis1)
Call oOcc1.CreateGeometryProxy(oPartPlane1, oAsmPlane1)
Call oAsmCompDef.Constraints.AddMateConstraint(oAsmPlane1, oAsmAxis2, Offset)
End Select
ErrH:
End Sub

Public Sub AddMateConstraint(ByVal EntityOne As Object, ByVal EntityTwo As Object, ByVal Offset As Double, ByVal strMateType As String, _
ByVal Plane1 As Integer, ByVal Plane2 As Integer)
On Error Resume Next
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
oOcc1 = EntityOne
oOcc2 = EntityTwo
oPartPlane1 = oOcc1.Definition.workplanes.item(Plane1)
oPartPlane2 = oOcc2.Definition.workplanes.item(Plane2)
Call oOcc1.CreateGeometryProxy(oPartPlane1, oAsmPlane1)
Call oOcc2.CreateGeometryProxy(oPartPlane2, oAsmPlane2)

Select Case strMateType
Case "Flush"
Call oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane1, oAsmPlane2, Offset)
Case "Mate"
Call oAsmCompDef.Constraints.AddMateConstraint(oAsmPlane1, oAsmPlane2, Offset)
End Select

End Sub

 

Can you help me to select correct "SelectionFilterEnum" for your function code

 

'Public Enum SelectionFilterEnum
'kPartEdgeFilter = 15873
'kPartEdgeCircularFilter = 15874
'kPartEdgeLinearFilter = 15875
'kPartEdgeMidpointFilter = 15876
'kPartFaceFilter = 15877
'kPartFacePlanarFilter = 15878
'kPartFaceCylindricalFilter = 15879
'kPartFaceConicalFilter = 15880
'kPartFaceToroidalFilter = 15881
'kPartFaceSphericalFilter = 15882
'kPartVertexFilter = 15883
'kPartFeatureFilter = 15884
'kPartSurfaceFeatureFilter = 15885
'kPartBodyFilter = 15890
'kPartDefaultFilter = 15886
'kSketchDimConstraintFilter = 16128
'kSketchCurveFilter = 16129
'kSketchCurveLinearFilter = 16130
'kSketchCurveCircularFilter = 16131
'kSketchCurveEllipseFilter = 16132
'kSketchCurveSplineFilter = 16133
'kSketchPointFilter = 16134
'kSketchDefaultFilter = 16135
'kSketchObjectFilter = 16136
'kSketchImageFilter = 16137
'kSketchTextBoxFilter = 16138
'kSketchProfileFilter = 16139
'kSketchProjectedCutFilter = 16140
'kSketchBlockDefinitionFilter = 16141
'kSketchBlockFilter = 16142
'kSketch3DCurveFilter = 17664
'kSketch3DCurveLinearFilter = 17665
'kSketch3DCurveCircularFilter = 17666
'kSketch3DCurveEllipseFilter = 17667
'kSketch3DCurveSplineFilter = 17668
'kSketch3DPointFilter = 17669
'kSketch3DDefaultFilter = 17670
'kSketch3DObjectFilter = 17671
'kSketch3DDimConstraintFilter = 17672
'kSketch3DProfileFilter = 17673
'kWorkAxisFilter = 16384
'kWorkPlaneFilter = 16385
'kWorkPointFilter = 16386
'kUserCoordinateSystemFilter = 16387
'kAssemblyOccurrenceFilter = 16640
'kAssemblyLeafOccurrenceFilter = 16643
'kAssemblyOccurrencePatternFilter = 16644
'kAssemblyOccurrencePatternElementFilter = 16645
'kAssemblyFeatureFilter = 16646
'kAllPlanarEntities = 18432
'kAllLinearEntities = 18433
'kAllPointEntities = 18434
'kAllCircularEntities = 18435
'kAllCustomGraphicsFilter = 18436
'kCustomBrowserNodeFilter = 18437
'kFeatureDimensionFilter = 18438
'kAllEntitiesFilter = 18439
'kDrawingDefaultFilter = 16896
'kDrawingSheetFilter = 16897
' kDrawingViewFilter = 16898
' kDrawingNoteFilter = 16899
'kDrawingDimensionFilter = 16900
'kDrawingPartsListFilter = 16901
'kDrawingHoleTableFilter = 16902
'kDrawingHoleTagFilter = 16903
'kDrawingRevisionTableFilter = 16904
'kDrawingCustomTableFilter = 16905
'kDrawingBalloonFilter = 16906
'kDrawingSketchedSymbolFilter = 16907
'kDrawingSketchedSymbolDefinitionFilter = 16908
'kDrawingAutoCADBlockFilter = 16922
'kDrawingAutoCADBlockDefinitionFilter = 16923
'kDrawingBorderDefinitionFilter = 16909
'kDrawingTitleBlockDefinitionFilter = 16910
'kDrawingBorderFilter = 16913
'kDrawingTitleBlockFilter = 16912
'kDrawingCurveSegmentFilter = 16914
'kDrawingCenterlineFilter = 16915
'kDrawingCentermarkFilter = 16916
'kDrawingSheetFormatFilter = 16917
'kDrawingFeatureControlFrameFilter = 16918
'kDrawingSurfaceTextureSymbolFilter = 16919
'kDrawingOriginIndicatorFilter = 16920
' kDrawingViewLabelFilter = 16921
'
End Enum

 

 

 

 

0 Likes