SolidWorks two times Development -06-add fit in assembly
After three days of tossing and finishing, the functional modules of the plan were finally completed. Automatically determine the insertion of suitable parts in an assembly and add a fit.
In the previous articles I have basically explained how to get the data information of the parts, how to insert the parts, how to get the selected features, etc.
The following only describes how to cooperate
In doing so, the need to often choose to the parts of the face, line, etc., this is a problem, there is to introduce the use of the ADDMATE2 function:
In general, we do this in the following order:
1-modeldoc.clearselection2 ' Cancel all options
2-Select the entity that needs to be matched (entity)
3-Use the ADDMATE2 function to cooperate
4-use Modeldoc.clearselection2 again to cancel all selections
The main question is how to choose the right face:
Because the name of the face is not a rule, many times is the program automatically named, so that is not convenient to use Selectbyid to choose, I do not want to use the coordinates of the value to select a face, that do worse.
When we get a component (component) or a feature (feature), we have getfaces, Getfirstface, Getnextface, and so on, and we can use these methods to traverse a component or feature, and so on, to achieve the purpose of the selection surface, Look at the following program:
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 a part Failed"
Selectface = False
Exit Function
End If
Set swdcface = swdowelbody. Getfirstface ' Get the first face
Do as not swdcface are nothing ' walks through each side
Set swdsurface = Swdcface.getsurface ' Get surface object
If Swdsurface.iscylinder Then ' if it's a cylindrical surface
IF TP = 0 Then ' means cylinder
Set swdent = Swdcface
Swdent.select4 True, Selddata
Selectface = True
Exit Function
End If
Else ' If it is the other, of course we may need to use Select to define many branches in practice
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 arguments, the first is a Component object, and the second identifies the selection type: 0 for the cylinder and 1 for the plane. When this function finishes running, it selects a face of the specified type for the specified component. It is to be noted that we need to convert to the surface object when judging the surface type. and select the need to define a entity object, used to SELECT4, to achieve the purpose of choice. Maybe this process is a little complicated, and you'll see how it works by testing it several times in this order.
The function above is not written well, it's a paragraph I intercepted from my project.
Distance value to use with Distance or limit mates
Distance
Input:
(double) Distabsupperlimit
Absolute maximum distance value (remarks)
Distance limit Max
Input:
(double) Distabslowerlimit
Absolute minimum distance value (remarks)
Distance Limit min
Input:
(double) Gearrationumerator
Gear ratio numerator value for Gear mates
Gear matching Molecular value
Input:
(double) Gearratiodenominator
Gear ratio denominator value for Gear mates
Gear matching Denominator value
Input:
(double) angle
Angle value to use with Angle mates
Angle
Input:
(double) Angleabsupperlimit
Absolute maximum angle value
Angle Limit Max
Input:
(double) Angleabslowerlimit
Absolute minimum angle value
Angle Limit min
Output:
(long) ErrorStatus
Success or error as defined by Swaddmateerror_e
Error Reporting
return:
(LPMATE2) Pmateobjout
Pointer to the Mate2 object
return pointer to fit
Remarks
To specify a distance mate without limits, set the Distabsupperlimit and Distabslowerlimit arguments Argument ' s value.
Specifies an unlimited distance, with the maximum, minimum and distance values equal to the distance limit set
If Matetypefromenum is swmatedistance or swmateangle then 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 .
If it is a distance or angle fit, the fit will be matched from the nearest end of the condition, we can set flip to true and change the fit to another suitable position.
Use: Using the steps to fit
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 mate is created.
If Matetypefromenum is swmatecamfollower, then use a selection mark's 8 for the Cam-follower face.
If the mating type is a cam, Mark 8 on the surface. Note: I don't quite understand that, haha
If It is preselected, then ErrorStatus are swaddmateerror_incorrectseletions and Pmateobjout is null/nothing.
If the implementation does not qualify the entity to match, it will be swaddmateerror_incorrectseletions, the function returns null or Nothing
The above is what the API helps say, and here's a sample program that says we've chosen a two-radius cylinder before, so let's define a concentric fit:
Note: There are times in programming to determine the type of an object, we can declare an object, let VB to match itself. But doing so is affecting efficiency.
To complete a distance or angle is a bit more troublesome, as explained in the remark above:
Here we need to set the Min and Max to be equal to the distance value, otherwise the coordination will think that we set the limit condition in the advanced coordination, will error. and the third parameter and the second parameter need to be determined according to the actual situation.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.