49 Replies Latest reply on Nov 13, 2017 10:22 AM by Deepak Gupta

    Custom properties

    Feroz Mahomed

      Is it possible to "extract" information from an excel file for a custom property in a drawing?

        • Re: Custom properties
          Deepak Gupta

          Yes the properties can be read from excel file via a macro.

          • Re: Custom properties
            Joop Sleumer

            Hello,

             

            It is also possible to use the Property Tab Builder (SW2010) to ad customproperties to your part or assembly

            These can be linked to the drawing then.

             

            With Regards

            Joop

              • Re: Custom properties
                Feroz Mahomed

                Joop,

                 

                How do i set the type to "excel file' as the only options Ihave are text,date & Yes/No.

                Also, how do I set the path and range? as these options are not available.

                 

                Thank you

                  • Re: Custom properties
                    Joop Sleumer

                    Hello,

                     

                    Make an exel file first

                     

                    If you start the Property Tab builder the screen has 3 columns.

                    From the first column you drag item List into a groupbox in the middle column.

                    Then in the right Colum you change Type to Exel File, then there appears a field to browse to your path

                    and a field to select a Range .

                     

                    Look into the help file of the Property Tab Builder.  (reference-> List Attributes)

                     

                    With regards

                    Joop

                • Re: Custom properties
                  Feroz Mahomed

                  Deepak,

                   

                  Where can i download such a macro?

                    • Re: Custom properties
                      Deepak Gupta

                      This macro support for external .ini file for Originator names (the files is in the macro itself)

                      http://www.sw.fcsuper.com/modules/UpDownload/shots/7.jpg

                      Click on the picture to download.

                        • Re: Custom properties
                          Feroz Mahomed

                          Deepak,

                           

                          This macro does not point to excel file for custom property.

                            • Re: Custom properties
                              Deepak Gupta

                              Yes this one doesn't and I just wanted to show you that you can link to an external file.

                               

                              From SW API help

                               

                              Because Microsoft VBA is embedded in the SolidWorks software, the SolidWorks  software is VBA-enabled and can inter-operate with other VBA-enabled  applications, such as Microsoft Excel, Microsoft Access, and Microsoft Visio.

                               

                              For example, you can create a VBA application in the SolidWorks software that  attaches to a running instance of Microsoft Excel. You can then  access the active sheet and retrieve data to use with the SolidWorks software.

                               

                              The following code shows how to attach to the active Microsoft Excel object, get the  value in cell A1 in the active sheet, and use that value to set the density in a  SolidWorks part.

                               

                              ' Attach to active Excel object

                              Set xl = GetObject(, "Excel.Application")

                              ' Get  active sheet in Excel

                              Set xlsh = xl.ActiveSheet  

                              ' Get  value in Excel cell  A1

                              density = xlsh.Cells(1,1)  

                              ' Set  density in SolidWorks part

                              Part.SetUserPreferenceDoubleValue  swMaterialPropertyDensity, density 

                               

                              Alternatively you can also attach to a running instance of the SolidWorks  software from a VBA application created in Microsoft Excel.

                               

                              In general, if your application is primarily a SolidWorks API application,  then develop the application in the SolidWorks software.

                              • Re: Custom properties
                                Deepak Gupta

                                Create one excel file with following details.

                                 

                                Excel.PNG

                                 

                                Then create a new macro and paste these codes

                                 

                                 

                                Dim swApp       As SldWorks.SldWorks
                                Dim swModel     As SldWorks.ModelDoc2
                                Sub main()
                                Set swApp = Application.SldWorks
                                Set swModel = swApp.ActiveDoc
                                ' Attach to active Excel object
                                Set xl = GetObject(, "Excel.Application")
                                ' Get  active sheet in Excel
                                Set xlsh = xl.ActiveSheet
                                ' Get  value from Excel cells
                                Name = xlsh.Cells(1, 1)
                                File = xlsh.Cells(2, 1)
                                Text1 = xlsh.Cells(3, 1)
                                Density = xlsh.Cells(3, 1)
                                'Add the Custom Property Name with value. Will not overwrite if there is nay existing property.
                                swModel.AddCustomInfo3 "", "Name", swCustomInfoText, Name
                                swModel.AddCustomInfo3 "", "File Name", swCustomInfoText, File
                                swModel.AddCustomInfo3 "", "Text1", swCustomInfoText, Text1
                                swModel.AddCustomInfo3 "", "Density", swCustomInfoText, Density
                                End Sub

                                 

                                 

                                Keep the excel file open and run the macro. The macro will add the Custom Property Name with values from Excel file. Will not overwrite if there is any existing property.

                                  • Re: Custom properties
                                    Feroz Mahomed

                                    Deepak,

                                     

                                    This macro works fine thus far as I am using it to insert barcodes from an excel file to a Solidworks drawing. Is it possible to add code to the macro to overwrite custom properties if they exist already or delete selected custom properties?

                                     

                                    Thank you

                                      • Re: Custom properties
                                        Deepak Gupta

                                        I don't know a way to overwrite but know how to delete them

                                          • Re: Custom properties
                                            Feroz Mahomed

                                            Deepak,

                                             

                                            Is there a macro to delete selected custom properties only?

                                              • Re: Custom properties
                                                Deepak Gupta

                                                Here you go

                                                 

                                                I have included the excel file also

                                                  • Re: Custom properties
                                                    Feroz Mahomed

                                                    Deepak,

                                                     

                                                    I have one more problem. I need the drawing to rebuild after the macro is run. I tried adding Part.EditRebuild3 at the end but this does not work.

                                                     

                                                    Thank you

                                                      • Re: Custom properties
                                                        Deepak Gupta

                                                        Add these lines

                                                        ' Rebild the drawing

                                                        swModel.EditRebuild
                                                        'Save the drawing (provided drawing has been saved earlier else it will prompt to save the drawing)
                                                        swModel.Save
                                                        above this line
                                                        swApp.SendMsgToUser ("Custom Properties Updated")

                                                         

                                                         

                                                        If you want to get ride of the msg that says "Custom Properties Updated", remove the above line

                                                          • Re: Custom properties
                                                            Feroz Mahomed

                                                            Deepak,

                                                             

                                                            Sorry for the delay in responding as I was on leave for a few days.

                                                             

                                                            The macro works fine now. However, a new problem has arisen. The macro works fine if I am importing barcodes for a new job as a new job would have the same number of fields in the excel spreadsheet. The problem now is when we remake a job, the number of fields in the excel spreadsheet are fewer than before as we would only be making some of the components.  See attachments for examples.

                                                             

                                                            Thank You

                                                          • Re: Custom properties
                                                            David Miller

                                                            Hi,

                                                            I just realized that your macro adds a custom property from excel to Solidworks.

                                                            I want to do just the oppositie.  I want to add a custom property to a cell in an excel spreadsheet that is embedded in the solidworks drawing.

                                                              • Re: Custom properties
                                                                Deepak Gupta

                                                                How about using a design table for it.

                                                                  • Re: Custom properties
                                                                    David Miller

                                                                    A design table would easily solve this problem, however, how do you embed a generic design table into a drawing template?  The design table has to be of a part.  Templates don't include parts.

                                                                     

                                                                    Another frustration I have is that I want to inlcude the BOM TABLE in my template, but the only way to include a BOM is if you have an assembly.

                                                                    Templates do not include parts or Assemblies, so how do you get around this problem?

                                                                      • Re: Custom properties
                                                                        Jiral Parikh

                                                                        I think you have got more reply if you have posted your question in API section.

                                                                        I am not sure what exactly you are trying to do. Look at the thread below.

                                                                        https://forum.solidworks.com/message/189706#189706

                                                                        in the very last posting, there is a tool available to extract properties and have them in excel sheet. However, this is only for parts and assemblies.

                                                                        If you simply want to extract properties from drawing and put them into excel sheet, that is very simple. I am not sure if this is what you are looking for.

                                                                        Few months ago, I have tried to get BOM into drawing template. At the end, I came to conclusion that it is not possible in SolidWorks. My VAR also confirmed that.

                                                                          • Re: Custom properties
                                                                            David Miller

                                                                            Hi,

                                                                            The thread you suggested refers to adding custom properties without opening solidworks.  That is not what I'm trying to do.  Also, I have posted to the API thread, but have not been able to get this issue resolved.

                                                                             

                                                                            From all the postings and macros, it seems as though what I'm trying to do can easily be done, but when I try these suggestions out, it isn't working.

                                                                             

                                                                            What I am simply doing is embedding an excel spreadsheet into a drawing template.  The spreadsheet is an "intelligent" tolerance block that will automatically display the correct 1,2,&3 decimal place tolerances for different "part types".  We have multiple part types that we fabricate, each of which has slightly different general tolerances and because we don't have a formal drafting department, with checkers, it is typically up to the engineer to check their own work (which is BAD) but unfortunately the mode of operation.  Additionally, many of the drawing creators have very limited knowledge of "good" design practice or understand tolerancing.  The result is parts do not meet spec, fail FAI, or problems occur in manufacturing when it's too late.  To help remedy some of these problems, we have formed a design committe to identify methods to improve our design process to address some of our shortcomings.  Automating the general tolerance block is one method It also can display the tolerances in inches, mm, or both, depending on what the users chooses for units.

                                                                             

                                                                            What I would like is to have a macro that allows the user to change the units, unit display, and part type.  If this information can be entered in the Custom Properties Tab, that would be a bonus, since the custom properties tab is used to add other information in the title block such as the creators name, Division Code, Finish, Checked By, Checked date, approved by, and approval date rather.

                                                                             

                                                                            As per a previous thread, this information can also be added/edited without having to open the part, assy, or drawing, however, this is approach has its limitations.

                                                                             

                                                                            Our plan is to migrate to EPDM, where all of these fields can be entered on the Data Card, however, in the interim, we need to continue to improve our method drawing control outside of EPDM.

                                                                              • Re: Custom properties
                                                                                Jiral Parikh

                                                                                so your main goal is to update your spreadsheet automatically based on what user picks and that spreadsheet is embedded as part of the drawing template.

                                                                                on the side, you want to add those picks in the custom properties as well.

                                                                                Is this correct?

                                                                                  • Re: Custom properties
                                                                                    David Miller

                                                                                    Yes,  That is exactly what I'm trying to do.

                                                                                    Here is pic of what it looks like today.

                                                                                    Picture1.png

                                                                                     

                                                                                    The user has to manually double click on the tolerance block to activate the spreadsheet.  "Part type is" and "Dimensions are in"  are currently validation tables.  Sometimes the spreadsheet view gets screwed up when users double click in it and start trying to change things they should, so it would be great if the user could just enter the properties from the custom properties tab in SW and have them automatically update in the embedded spreadsheet.  I would be ok, with them updating when the user updates the drawing.  The other thing that would be absolutely ideal, is for the units to change based on what the user selects.  For all of our SW templates, the default units are mm, however, if the user wants to change units to inches, all they have to do is select inches and selects inches, the drawing units will change to inches.  If they select mm (inches), then dual dimensioning will get turned on. This way, the user enters what they want in one place only.

                                                                                      • Re: Custom properties
                                                                                        Jiral Parikh

                                                                                        David

                                                                                         

                                                                                        In our company, we use a tool called "customworks 5". This has been designed by a solidworks reseller in finland. An amazing tool. Not that I am trying to promote this tool, as a user of this tool, I can tell you that it can take care of everything you have asked. If this is the only reason that you guys are switching to EPDM, then it is not a good move. The tool is not that expensive. It cost us around $15,000 for 20 seats. Here is the website and you can get trial version of it first.

                                                                                         

                                                                                        http://www.cadworkssoftware.com/

                                                                                         

                                                                                        Check this out first. Amazing thing about this tool is that you customize whatever way you want. Then, it has a programming interface in  he background. So, based on what you pick as first property, this tool can go through program and generates other properties based on your selected property. Instead of excel sheet, you can have simple table (like title block) and all those properties will be added in that table.

                                                                                         

                                                                                        If you are interested, I can show you some screen shots from my solidworks.

                                                                                         

                                                                                        Good luck,

                                                                                          • Re: Custom properties
                                                                                            David Miller

                                                                                            We have been evaluating EPDM for the past 3-4 months.

                                                                                            At first I did not like it, however, I've come to realize it has alot of strengths.  It can't do everything I want it to, but I do like the workflow aspects of it (using it...not programming it).  It's still just a dumb database manipulator, however, so if there's something else out there that can do everything EPDM can do plus "intelligent" stuff that EPDM will likely never be able to do, I'm interested.

                                                                                              • Re: Custom properties
                                                                                                Jiral Parikh

                                                                                                customworks 5 is not a data management tool, it is a simple property tab builder and there are lot of other property tab builder softwares are available in the market. Just like solidworks has itw own property tab builder.

                                                                                                The advantage it has over everyone else is that having programming interface in the background which allows you to generate more properties in the background.

                                                                                            • Re: Custom properties
                                                                                              Deepak Gupta

                                                                                              If I can ask, what if you set different file templates based on the units requirements.

                                                                                                • Re: Custom properties
                                                                                                  David Miller

                                                                                                  We currently have 20+ something drawing templates.  Do you know what my biggest complaint is from users?  you guessed it.  There's too many templates, but yet every engineer in the company wants to have their own customized template.  Well, that's what everyone did in the past.  There was no ONE standard.  I have tried to please everyone, which I've discovered is impossible to do, and presently, as we try to become more standardized globally, the drawing templates are still changing as users are getting used to working with them.  Therefore, if I have to change ONE Template.  I have to change 20.  Everytime another variation is added to distinguish a different drawing template, it creates a proliferation of drawing templates.  I can easily see those 20 templates growing to 60 templates, just for the sake of having different drawing units.

                                                                                                  I think Solidworks can do the user community a great good by improving their drawing wizard, so when you click on Make Drawing from part/assembly, a wizard pops up that allows you to enter all the fields needed to build a drawing template on the fly, such as drawing size, units, part type, 1st or 3rd angle projection, etc.  If a user wants to save a template, give them that choice.

                                                                                • Re: Custom properties
                                                                                  Michele Craig

                                                                                  Deepak,

                                                                                   

                                                                                  This macro is just what I have been looking for!  Have you created a similar macro that will work with .sldprt & .sldasm files as well?  Or, how do I modify the macro to work with those file type's properties as well?

                                                                                   

                                                                                  Thank you,

                                                                                  Michele

                                                                                    • Re: Custom properties
                                                                                      JOHN GEORGE

                                                                                      Michele,

                                                                                      How about using property tab builder within SolidWorks.

                                                                                      It's a very nice program. You can create any type of properties for parts, assemblies and drawings

                                                                                       

                                                                                      Check this discusssion

                                                                                      https://forum.solidworks.com/message/243100#243100

                                                                                      • Re: Custom properties
                                                                                        Deepak Gupta

                                                                                        You need to add the codes for file types and then it should be good to use. I can fix it up if you need

                                                                                         

                                                                                        I would also suggest to look at property tab builder as suggested by John

                                                                                          • Re: Custom properties
                                                                                            Jason McCrory

                                                                                            Deepak -

                                                                                             

                                                                                            Michele and I are in the same company/dept - She passed along the information to me and I'm working on adapting it to our needs (thanks for the macro BTW - Good stuff!).

                                                                                             

                                                                                            When I run the macro (as delivered - no modifications) I get a compile error - "cannot find object or library" at this line:

                                                                                             

                                                                                            ' Attach to active Excel object

                                                                                            Set xl = GetObject(, "Excel.Application")

                                                                                             

                                                                                             

                                                                                            Any help you could point me to would be super... We're using SWX2012 on WinXP.

                                                                                             

                                                                                            Thanks!!

                                                                                             

                                                                                             

                                                                                            --Edit--

                                                                                            Also - We already use the property tab builder - but we're looking at ways to expand our document automation with tools we already have, and this particular macro has loads of potential.

                                                                                             

                                                                                            Thanks again!

                                                                                             

                                                                                            Message was edited by: Jason McCrory

                                                                                              • Re: Custom properties
                                                                                                JOHN GEORGE

                                                                                                Jason,

                                                                                                 

                                                                                                Thanks for the input.

                                                                                                 

                                                                                                We use the property tab builder for 90% of our part, assembly and drawing fill-in data.

                                                                                                You can get the most common standard properties either from MS excel or MS access file.

                                                                                                You could add or modify these info at any time.

                                                                                                Please look at the attached pictures showing one of the sample properties for part and drawing we use.(Populated thru the property tab builder)

                                                                                                 

                                                                                                For Part Properties


                                                                                                sw-propertytab-part.png

                                                                                                 

                                                                                                For Drawing Properties

                                                                                                sw-propertytab-draw.png

                                                                                                 

                                                                                                All the drop down tabs are populated from a database.

                                                                                                • Re: Custom properties
                                                                                                  Deepak Gupta

                                                                                                  Check if the way John has explained the use of Property Tab builder works for you or not. In case you want to use the macro then edit the macro (Tools > Macro > Edit and point to this macro) and go Tools > References in the macro editor window. Look for any missing libraries. Uncheck them and select the corresponding one.

                                                                                                   

                                                                                                  John thanks for explaining

                                                                                                    • Re: Custom properties
                                                                                                      Jason McCrory

                                                                                                      **I fixxed the compile error I had BTW... it was a missing reference that I simply unchecked.

                                                                                                       

                                                                                                      We make use of the property tab builder - It has been especially helpful for us with our parts library.

                                                                                                       

                                                                                                      We manufacture vacuum systems using mostly 'off the shelf' components. We model the components and store them in our PDM library, and over time have built up a massive repository of parts. We have some typical data points (our part number, vendor, vendor part number, etc...) that we add to the custom properties for every part in our library, and the property tab builder has helped immensly to 'normalize' that information and make it easier to input.

                                                                                                       

                                                                                                      Our systems are modeled as a 'top-level' assembly, and we generate two different drawings from this assembly. We populate the drawing properties manually with the information about the system so that the properties are resident in the drawing file and are searchable in WPDM (the engineers only have access to the drawings, not the models themselves). This means that the same properties are entered 2~3 times for every system (in SolidWorks alone). Part of our department's recent efforts involve reducing the amount of redundant data entry we do, so this macro is a great help. We maintain Excel based 'Project Data Sheets' for every job we do; These are stored on the network so anyone in the department can check and update them as needed. This macro allows our designers to grab data already entered in that file and have it populate to the properties.

                                                                                                       

                                                                                                      I am curious if there is a way to:

                                                                                                       

                                                                                                      1. Launch an "Open File" dialog to pick an choose an excel file rather than have to have one open and active (small thing, I know - but convenient).
                                                                                                      2. Look at a specific sheet in the excel file (as opposed to just the active sheet).
                                                                                                      3. Used named cells/data instead of coordinates for retrieving data.

                                                                                                       

                                                                                                      I'm sure these things are possible, I just have to find the right syntax... if anyone has 'quick' answers they'd like to share, I'd be most grateful...

                                                                                                       

                                                                                                      Thanks again for the macro and all the help!

                                                                                      • Re: Custom properties
                                                                                        Márton Sápi

                                                                                        Is it possible, that when i change sg in the excel, it automatically writes over the custom properties of the SW?

                                                                                         

                                                                                        Thanks.

                                                                                          • Re: Custom properties
                                                                                            Deepak Gupta

                                                                                            You can use a design table (linked to external excel file) to update the properties OR can run a macro to get the values form excel and update to model properties.

                                                                                              • Re: Custom properties
                                                                                                Márton Sápi

                                                                                                And how can I do that?
                                                                                                I  wrote a macro but its not good. I can write the name of the property and I can import datas from an active excel, but I cant overwtite the property. e.g if i change the value in the excel, it wont appear in the properties.
                                                                                                What I want is a macro, and when i change sg in the excel it would change in the SW properties.

                                                                                                 

                                                                                                Thanks

                                                                                                  • Re: Custom properties
                                                                                                    Deepak Gupta

                                                                                                    Can you share a sample file, excel file and the macro you're trying to use.

                                                                                                      • Re: Custom properties
                                                                                                        Márton Sápi

                                                                                                        Dim swApp       As SldWorks.SldWorks

                                                                                                        Dim swModel     As SldWorks.ModelDoc2

                                                                                                        Sub main()

                                                                                                        Set swApp = Application.SldWorks

                                                                                                        Set swModel = swApp.ActiveDoc

                                                                                                        Set xl = GetObject(, "Excel.Application")

                                                                                                        Set xlsh = xl.ActiveSheet

                                                                                                        Name = xlsh.Cells(1, 1)

                                                                                                        File = xlsh.Cells(2, 1)

                                                                                                        Text1 = xlsh.Cells(3, 1)

                                                                                                        Density = xlsh.Cells(4, 1)

                                                                                                        swModel.AddCustomInfo3 "", "Text=xlsh.Cells(1, 2)", swCustomInfoText, Name

                                                                                                        swModel.AddCustomInfo3 "", "File Name", swCustomInfoText, File

                                                                                                        swModel.AddCustomInfo3 "", "Text1", swCustomInfoText, Text1

                                                                                                        swModel.AddCustomInfo3 "", "Density", swCustomInfoText, Density

                                                                                                        End Sub

                                                                                                         

                                                                                                         

                                                                                                        I found it here, not i wrote it. i m new at macros, so I jve just tried to change it.
                                                                                                        What I want is link the text field in Drawing from the properties, and I want to import the properties from excel.

                                                                                                          • Re: Custom properties
                                                                                                            Deepak Gupta

                                                                                                            Try these codes. Make sure you add reference to excel library. Modify as needed

                                                                                                             

                                                                                                            Option Explicit

                                                                                                            Dim swApp           As SldWorks.SldWorks

                                                                                                            Dim swModel         As SldWorks.ModelDoc2

                                                                                                            Dim swCustProp      As CustomPropertyManager

                                                                                                            Dim xlApp           As Excel.Application

                                                                                                            Dim xlWs            As Excel.Worksheet

                                                                                                            Sub main()

                                                                                                               

                                                                                                            Set swApp = Application.SldWorks

                                                                                                            Set swModel = swApp.ActiveDoc

                                                                                                            Set swCustProp = swModel.Extension.CustomPropertyManager("")

                                                                                                             

                                                                                                            Set xlApp = GetObject(, "Excel.Application")

                                                                                                            Set xlWs = xlApp.ActiveSheet

                                                                                                             

                                                                                                            swCustProp.Add3 "Name", 30, xlWs.Cells(1, 1), 1

                                                                                                            swCustProp.Add3 "File", 30, xlWs.Cells(1, 2), 1

                                                                                                            swCustProp.Add3 "Text1", 30, xlWs.Cells(1, 3), 1

                                                                                                            swCustProp.Add3 "Density", 30, xlWs.Cells(1, 4), 1

                                                                                                             

                                                                                                            End Sub

                                                                                          • Re: Custom properties
                                                                                            Parminder Singh

                                                                                            So, is there some way we can import Custom Properties from MS Access Database