SolidWorks two times development -05-assembly body insert Parts
Source: Internet
Author: User
Insert SolidWorks Two development--insert parts in assembly
When inserting parts into the assembly, we use the addcomponent function. If you need to configure the selected parts, you need to use ADDCOMPONENT4.
Learn the grammar first:
ADDCOMPONENT4:
retval = Assemblydoc.addcomponent4 (Compname, ConfigName, x, Y, z)
Input: (BSTR) compname Path name of a loaded part or assembly to add as a component
Input: (BSTR) ConfigName Name of the configuration from which to load the component
Input: (double) x x coordinate of the component center
Input: (double) y y coordinate of the component center
Input: (double) z z coordinate of the component center
Output: (LPCOMPONENT2) retval pointer to the Component2 object
Note that parameter 1 is the full name of the file (including the path), parameter 2 is the file's configuration name, and a pointer to the part is returned when the function is executed successfully.
So we can write a small program to insert parts into the assembly:
' Filename:insertPart.swp
' Write by
Arden
2005-4-4
' This function add a parts called ' Part 1. Sldprt "in Currentworkingdirectory
' Precondition is there has a parts document called ' Part 1. Sldprt "in Currentworkingdirectory
' And it has a configuration called ' Configuration 1 '
Dim Swapp as Sldworks.sldworks
Dim Model as ModelDoc2
Dim PTH as String
Dim strpath as String
Sub Insertpart ()
Set Swapp = Application.sldworks
strpath = Swapp.getcurrentworkingdirectory ' Current work path
Set Model = Swapp.activedoc
PTH = strpath & "Part 1. Sldprt "' Get the FullPath full name of the file
MODEL.ADDCOMPONENT4 PTH, "Configuration 1", 0, 0, 0 ' Add parts
End Sub
However, this program is not as useful as it is imagined. Why?? Looking back at Addcomponent4 's remark, it says:
The specified file must is loaded in memory. A file is loaded to memory when your load the file in your
SolidWorks session (SLDWORKS::OPENDOC6) or open a assembly that already contains the file.
So you want to specify that the inserted file must be loaded in memory before the function is called.
Not accustomed to, you can not directly open how simple, no way, I have not found a good way, can only be according to others:
Look at the following function Opendoc6, which opens a document:
ysbmodel.visible = False ' I don't want to see part 1
End Sub
This way I feel more stupid ~ in order to catch the project progress I did not look for a good way, if you know there is a good way to tell me, extremely grateful.
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.