Click on a part in design tree and print drawing using macros?

I need to print stuff in order. I want to click on a part in design tree and print the drawing. For example, the one below.

Would anyone please give me some directions?

SolidworksApi macros
Answers 6
JB
JB 2017-04-27 Best Answer

If you are not using PDM, SolidWorks has no way of knowing what drawing you want to print when you click on a component in an assembly.  There is no "link" from part to drawing, only from drawing back to part.  Therefore, you (the programmer) must know where all the files reside that might be linked to the part.  Oh, and what happens it 2 drawings are linked to that part?  You can create as many drawings as you want of one part.  You can create views of that part in a drawing of a completely different part.  You must know, as the programmer, how all your files are created and stored.  Then, you can write a program to look in those places for files.  You can then have SolidWorks check those files to see if they reference the part. 

Or, if you are lazy and have good people who can follow standards, make a standard naming rule and look for the right filename. 

CC
CC 2017-04-27

As ​mentioned, you can create many drawings from one part; however,  you can open only one (1) drawing from  a part (not from  open dialog box) if the file names of part and dwg are identical.  If there is any one missing character such as space, SW can't find the dwg from a part for you - Try it and you'' see !!!

That's said, you can get the document name from part and use that name with extension .slddrw for your tasks such as print or open

MM
MM 2017-04-28

I am using EPDM

Currently, the name of the part has standard. It must be 10 digits number.

So what I want is a program to know which part number in the design tree that I selected and then print the corresponding drawing if the drawing is exist.

FS
FS 2017-04-28

Hi Marco, this can be done with CUSTOMTOOLS (even if you use SW PDM or not). You are able to select one or multiple files from the SOLIDWORKS Design tree and print them directly without having to open the parts or its drawings. If you have multiple drawings then it is not an issue as all the referred drawings are automatically found, no matter how you have named them (part and drawings name can be different) or where you have stored them (Part and drawing folder can be different). In addition, printing is managed via profile so you are able to define print settings (Printer, paper size, orientation, scaling,...). There is a video available on YouTube in case you are interested.

MM
MM 2017-04-29

I created a macro. It almost does the function.

However, it does not open the drawing file that I want. It just stayed at assembly level and then print the assembly screen.

I am sure that the drawing file is checked out. Do you have any idea? Please see the attached swp file

MM
MM 2017-04-29

I created a macro. It almost does the function.

However, it does not open the drawing file that I want. It just stayed at assembly level and then print the assembly screen.

I am sure that the drawing file is checked out. Do you have any idea? Please see the attached swp file