11 Replies Latest reply on Nov 13, 2012 11:33 PM by Keith Rice

    Pack and Go Suffix auto-fill with custom properties

    Jason Corl

      Hello, I'm wondering if anyone has created a macro to use or mimic the function of the pack and go tool where an entire assembly (and its sub assemblies) can be copied and the files could be saved adding a prefix or suffix built from custom properties?

       

      For example I have custom property Revision. I want to pack and go my assembly and have the files automatically saved with the suffix built from custom properties while maintaing references, this way Widget.sldprt would be saved to Widget (Rev A).sldprt, or Widget (Rev A) PN 12345.sldprt etc. Where "A" and "12345" are automatically filled out unique for each part.

       

      We use a pdm system and there's not a great need for this locally, but when sending files out to a vendor etc. who doesn't have a pdm system, they have no idea if they have the latest version without checking file properties and most of our vendors don't know how or want to do that, they just want us to send them a file that is usable and keep the system simple.

       

      Ideas? Thanks,

        • Re: Pack and Go Suffix auto-fill with custom properties
          Keith Rice

          Edit: Attachment removed, please see newest version of macro, called "Create pack and go with specified custom property as prefix" in our Macro Library.

           

          Hi Jason,

           

          This is pretty easy to accomplish using the IPackAndGo interface. The attached macro accomplishes this. It saves the new files, however, to the source directory(ies), which may be inconvenient. Taking it to the next level (specifying a folder, controlling formatting, etc) would be more time consuming so contact me at my web site if you're interested in going that route.

           

          To run the macro, first make sure your assembly is open and then go to Tools-->Macros-->Run. Browse for the .swp file and click Open.

           

          Keith

          Video Tutorials for the SolidWorks API

            • Re: Pack and Go Suffix auto-fill with custom properties
              Jason Corl

              Hey Thanks Keith,

               

              I'll check this out and get back to you. I signed up for yoru site a while ago but can't afford a full package yet. Thanks again.

              • Re: Pack and Go Suffix auto-fill with custom properties
                Jason Corl

                Hey Keith,

                 

                I tested this on a small assembly and it seems that it doesn't append the individual parts revision to each file name. I only have 1 top level assembly and 4 parts but it seems to have added the revision of that top level assembly to each of the sub parts.

                 

                I was looking for it to add each component's actual revision, so the assembly might be rev 2, but the parts in it might be at rev, 4, 5, 6 respectively and I would need the parts to be saved with rev 4, 5, 6, but the assembly with rev 2. Is that still possible?

                 

                Thanks again for your help!

                  • Re: Pack and Go Suffix auto-fill with custom properties
                    Keith Rice

                    Yes, it is possible. Use IComponent2::GetModelDoc2 to retrieve the pointer to each component's IModelDoc2 object, then you can get the ICustomPropertyManager object and consequently get the Revision custom property.

                     

                    Edit: I have modified the macro I previously created to add the suffix according to the Revision property unique to the document. The macro also now works on drawings, and you can specify the custom property and output folder you want if you edit the constants at the beginning of the code. You can get it here. It is called "Create pack and go with specified custom property as prefix". It requires a free membership to my site.

                     

                    Keith

                    Video Tutorials for the SolidWorks API

                      • Re: Pack and Go Suffix auto-fill with custom properties
                        Jason Corl

                        Wow that's awesome Keith, thank you so much for putting that together. I'm still going to play around with it and see if I can take it a few more steps now that I see it can definitely be done. This will help immensely.

                         

                        Do you feel that someone who completes your "course" on CADSharp.com would have the tools and understanding necessary to create this type of a macro upon completion?

                         

                        Thank you!

                          • Re: Pack and Go Suffix auto-fill with custom properties
                            Keith Rice

                            Hi Jason,

                             

                            First, I am not certain why it is not including drawings. I have tested it on my end and I am having the same issue. I'll look into it.

                             

                            My course is designed to take the complete programming novice to a high level of prociency with the SolidWorks API as applied with VBA macros. Consequently, the macro I have written is something you could do on your own once you understood the material covered in the following videos: Unit 1 (VBA programming essentials), Unit 2 (SolidWorks API fundamentals), and 3.3 (custom properties). I also discuss using the IPackAndGo interface briefly in lesson 5.2 (working with existing assemblies). Of course, some practice would be helpful before trying to take on this macro on your own, and for that reason you would probably study additional videos like those in Unit 3, do the homeworks, exploring relevant macros in the Macro Library, and so on.

                             

                            You would definitely not need to watch every single video, however, to be able to write complex macros. Beyond the first three units, its really up to you what you want to study. If you have no interest in automating drawings, skip unit 6. Likewise with units 4, 5, and 7. Most people treat those last four units like a buffet---and that's perfectly fine.

                             

                            Looking at it another way: a proficient API programmer, perhaps using my web site as a reference, could write this macro in an hour or two.

                             

                            Keith

                            Video Tutorials for the SolidWorks API

                              • Re: Pack and Go Suffix auto-fill with custom properties
                                Jason Corl

                                Hey Keith,

                                 

                                Thanks for looking into it. I looked at a few other macros using the IPackAndGo api and found the same syntax so I wasn't able to figure it out either. I'm on 2013 win7 x64 if that matters at this point.

                                 

                                I just installed VS-VB.NET Express and C# Express and I'm reading an intro to VB.net book now (Teach yourself VB.NET 2010 in 24hrs) and so far its really good, teaching me a lot of the fundamentals I've questioned for a while that I feel were preventing me from really diving in. Once I get my feet wet there a bit more I'll dive more heavily into the SW API and work on applying that to my VB.NET ventures. Hopefully I'll be able to try out your site for a month and cram in what I can.

                                 

                                I found the other thread in the forums where another user was having an issue with drawings also and you had recommended this macro that you wrote. not sure if it worked out for him but where it left off in the thread still seemed unanswered. Maybe the same issue?

                                 

                                Anyone to ask at SW to make sure its not a bug?

                                 

                                Thanks again for your help on this, I'll keep pecking away too.

                            • Re: Pack and Go Suffix auto-fill with custom properties
                              Jason Corl

                              Hey Keith,

                               

                              Can you check if the macro is working with drawings also? I can't seem to get it to save the referenced drawings, either to the parent assembly or to a child part.

                               

                              I checked and saw that swPackAndGo.IncludeDrawings = True

                               

                              Am I missing something?

                               

                              Thanks!

                            • Re: Pack and Go Suffix auto-fill with custom properties
                              Artem Taturevych

                              I would definitely suggest you to use Document Manager for these purposes. It is relatively simple to reproduce the Pack&Go functionality and adapt it for your needs. Use SwDMApplication::CopyDocument to copy documents. Please note this method allows renaming the destination files (including children) keeping the references.

                               

                              You still can get all components of the assembly and the specific custom property.

                               

                              So general workflow should look like this:

                               

                              1) Get assembly document: SwDMApplication::GetDocument.

                               

                              2) Get All components from this assembly ISwDMConfiguration2::GetComponents

                               

                              3) Get the document for every component SwDMComponent4::GetDocument2.

                               

                              4) Get the required custom property value: SwDMDocument::GetCustomProperty.

                               

                              5) Update the names

                               

                              6) Call SwDMApplication::CopyDocument to pack the files and rename them

                               

                              It would be good to additionally implement unique document check and so on. But in general it should look like this.

                               

                              Note in order to use SolidWorks Document Manager you should request the key from SolidWorks API Support. This key is free.

                               

                              Using of DM is preferable in this case cause this will significantly increase the performance furthermore this tool may be used without SolidWorks.

                               

                              ______________________

                              Regards,

                              Artem Taturevych

                              Application Engineer at Intercad

                              http://intercad.com.au/

                              Tel: +61 2 9454 4444