SOLIDWORKS Secondary Development -06-Add Team in the loading ligand
Torting for three days, finally completed the functional modules in the plan. The insertion of the appropriate part is automatically judged in a loader and adds a cooperation.
In the previous article, I have basically explained how to get data information of the component, how to insert components, how to get the selected features.
Let's only introduce how to cooperate
When you do a match, you need to choose the face, line, etc. of the part, this is a problem, and it is to introduce the use of Addmate2 function:
Generally, cooperation with us in accordance with the order below:
1-modeldoc.clearselection2 'Cancel all options
2 - Choose the entity that needs to be cooperated (Entity)
3- Cooperate using the addmate2 function
4- Using ModelDoc.clearselection2 'again Cancel all options
The main problem is how to choose the right surface:
Due to the naming of the face, many times are the program automatic to name, so it is not convenient to use SelectByid to choose, I don't want to use the coordinate value to choose one side, which is even worse.
When obtaining a component (Component) or a feature, we have getFaces, GetFirstFace, GetNextFace, etc. :
Private function selectface (DCOM As SLDWORKS.COMPONENT2, TP AS INTEGER) AS Boolean
Set SwdowelBody = DCOM.GetBody ()
If SWDOWELBODY IS NOTHING THEN 'error handling
Msgbox "Select Part Failure"
SELECTFACE = FALSE
EXIT FUNCTION
END IF
Set Swdcface = SWDOWELBODY.GETFIRSTFACE 'Get the first side
Do While Not Swdcface Is Nothing 'Traces all faces
Set swDSurface = SWDCFACE.GETSURFACE 'Get surface objects
If SWDSURFACE.ISCYLINDER THEN 'If it is a cylinder
IF TP = 0 THEN 'Means Cylinder
Set SWDENT = SWDCFACE
SWDENT.SELECT4 TRUE, SELDDATA
SELECTFACE = TRUE
EXIT FUNCTION
END IF
Else 'If it is other, of course, we may need to use Select to define a lot of branches.
IF TP = 1 THEN 'Means Plane
Set SWDENT = SWDCFACE
SWDENT.SELECT4 TRUE, SELDDATA
SELECTFACE = TRUE
EXIT FUNCTION
END IF
END IF
Set SWDCFACE = SWDCFACE.GETNEXTFACE
Loop
END FUNCTION
This function accepts two parameters, the first is a Component object, the second use to identify the selection type: 0 means the cylindrical surface, 1 means a plane. This function will select one of the specified types of the specified type of the component after this function is complete. It should be noted that we need to switch to the Surface object when it is the type of judgment. And choose to define an Entity object, used to select4, to achieve the purpose of the choice. Maybe this process is a bit complicated, and you will test a few times according to this order, you will understand its working principle. The above function written is not good, it is a piece taken from my project.
Let's introduce Addmate2 functions:
SYNTAX (OLE Automation) OLE syntax:
pMateObjOut = AssemblyDoc.AddMate2 (mateTypeFromEnum, alignFromEnum, flip, distance, distAbsUpperLimit, distAbsLowerLimit, gearRatioNumerator, gearRatioDenominator, angle, angleAbsUpperLimit, angleAbsLowerLimit, errorStatus)
parameter:
Input: (long) mateTypeFromEnum Type of mate as defined in swMateType_e with type Input: (long) alignFromEnum Type of alignment as defined in swMateAlign_e alignment options Input: (VARIANT_BOOL) flip TRUE to flip the component, FALSE otherwise whether Flip Input: (double ) distance distance value to use with distance or limit mates distance Input: (double) distAbsUpperLimit Absolute maximum distance value (see Remarks) distance limitation max Input: (double) distAbsLowerLimit Absolute minimum distance value (see Remarks) distance limitation min Input: (double ) gearRatioNumerator gear ratio numerator value for gear mates gear with the numerator value Input: (double) gearRatioDenominator gear ratio denominator value for gear mates gear mating denominator value Input: (double) angle angle value to use with angle mates angle Input: (double) angleAbsUpperLimit Absolute maximum angle value angle limiting max Input: (double) angleAbsLowerLimit Absolute minimum angle value angle limiting min Output: (long) errorStatus Success or error as defined by swAddMateError_e error report Return: (LPMATE2) pMateObjOut Pointer to the Mate2 obj ECT returns a pointer to the fitting
Remarks
To Specify A DISTANCE MATEOUT LIMITS, SET The distabsupperlimit and distabslowerlimit arguments equal to the distance argument's value. Specify a distance without a restricted distance, set the maximum, minimum and distance values of the distance limit
If mateTypeFromEnum is swMateDISTANCE or swMateANGLE when the mate is applied to the closest position that meets the mate condition specified by distance or angle, then setting flip to TRUE moves the assembly to the other possible mate position.
If it is a distance or angle, the cooperation will cooperate from the closest end of the eligible, we can set flip to true, change the cooperation to another suitable location
Use: Steps to use
Modeldoc2 :: Clearselection2 (variant_true) Before Selecting Entities To Mate.
ModelDocextension :: SELECTBYID2 with MARK = 1 TO SELECT Entities To Mate.
Modeldoc2 :: Clearselection2 (variant_true) after the name is create.
IF MateTypeFroenum Is Swmatecamfollower, The Use a Selection Mark of 8 for the cam-follower face.
If the mating type is a cam, sign 8. Note: I don't quite understand this.
If Nothing is prepselected, The Errorstatus is SwaddmateError_incorRectSeleTs and PmateObjout is null / nothing.
If the implementation does not have a qualified entity, it will be wrong with SwaddMateError_incorRectSeletions, the function returns null or Nothing
The above is what the API helps, the following example program is given, and we have chosen the same cylindrical surface of the two radiors before, then we will define a concentric cooperation:
Set swamatefeat = swassy.addmate2 (1, 0, false, 0, 0, 0, 0, 0, 0, 0, 0, nerror)
Among them, DIM SWASSY As SLDWORKS.ASSEMBLYDOC
DIM SWMATEFEAT AS Object
Note: It is time you sometimes determine the type of object, we can declare an Object object, let VB do it yourself. But this is affecting efficiency.
To complete a distance or angle, you should have trouble, just as in the Remark above:
Set swamatefeat = swassy.addmate2 (5, 1, true, 0.001, 0.001, 0.001, 0, 0, 0, 0, 0, nerrors)
Here we need to set MIN and MAX to be equal to distance values, or otherwise we will think that we set the restriction conditions in advanced cooperation, will report an error. And the third parameter and the second parameter need to be determined according to the actual situation.
Finally, we list the type of addmate2:
SWMATETYPE_E
'Specifies Values for Assembly-Mate Information.swmatecoinCide 0
SWMATECONCENTRIC 1 concentric
SWMATEPENDICULAR 2 vertical
SWMATEPARALLEL 3 parallel
SwmateTangent 4
SwmatedInsAnce 5 distance
SWMATEANGLE 6 angle
SWMateunkNown 7 unknown
SwmateSymmetric 8 symmetrical
SWMATECAMFOLLLOWER 9 cam
SWMategear 10 gears