13 Replies Latest reply on Oct 27, 2014 3:54 AM by Andries Koorzen

    Conditional Data card

    James Guilford

      I'm in process of designing a data card that takes the input from user (list) and refers to an excel documents and prompt the user to enter more information based on their choice. For example.

       

      In the data card the user has to choose the equipment type , when chosen lets say ( Bolts) then in excel file there are sub categories for Bolts Types, Material, size, vendor, manufacture and etc.

       

      When the user select the equipment type, I'd like to be able to refer to the excel file and have the user to select the type only with respect to those values.

       

      Equipment Type : Bolt ----> Size:3m ----> manufacture : ABC -----> Material : XYZ -----> and so on

       

      I tried List, however I could not set conditional sub categories for it. Any help is appreciated.

       

       

      Cheers,

       

      James

        • Re: Conditional Data card
          James Guilford

          Update: I tried doing this using list and alias, however, since I have a large list of data it seems  inefficient to use this method, as the list is expanding all the time!

           

          Would I be able to do this using the API? So that the API refers to the excel and then prompts for those information?  this would solve the problem of changing list aliases in the EPDM ?

           

          Thanks

            • Re: Conditional Data card
              Andries Koorzen

              Hi James.

               

              Simply put, alias lists are only for smaller applications that require the user to setup 'once off' lists or manage lists that don't update too frequently.

              If you need to continually expand the list, and the lists dependant thereon, then an Excel file might be the option and yes - you can do it with the API

               

              If you are going to write an application, you might also look into storing the file contents straight in the database or creating a 'Linked server' to the excel file.

              This allows you to write a SQL query in the EPDM Administration list tool to get the list of entries straight from the Excel file (Search for OPENROWSET)

               

              44.jpg55.jpg

               

              Just do a general search for 'sql linked server excel'. It will give you what you're looking for.

              Remember - This is only since you are considering the fact that you'll be coding / using the API. Be prepared for many days of troublshooting your own stuff, but also for great reward should it work!

                • Re: Conditional Data card
                  James Guilford

                  Thanks for the reply Andries.

                  I understand that SQL only pulls in one column at a time, Would I Still be able to set aliases?

                  How do you suggest I approach this, I've never had any experience with SQL, VBA ? Do you have any good learning resources you can refer me to?

                    • Re: Conditional Data card
                      Tim Read

                      I can't remember where I got this from but I know that it's from Joy Garon...


                      I think it'll contain most of what you need to get you started and a nice little movie also :-)

                      • Re: Conditional Data card
                        Andries Koorzen

                        Hi James.

                         

                        If you have never coded - consider getting your VAR involved to create the add-in for you, or hiring a programmer

                        If you VAR does not have a programmer available or you feel very enthusiastic about exploring new avenues (Note: Not all VARs will have one because we're not in the programming industry (I work for a VAR in South Africa + am a programmer)), I would suggest:

                         

                        • You obtain a copy of the EPDM API guide (available from your VAR)
                        • Download Visual Studio Express 2013 (Free / Express edition is more than enough for what you need)
                        • Watch the tutorial by Joy Garon on how to create a list addin (Kudos to her + Joy if you're reading this - I reposted the video from a old saved file - couldn't find your original post)
                        • Get the code from the video by reading the manual
                        • Get some SQL understanding - not too difficult for what you're attempting - might take you a quick 5 weeks
                        • Be very prepared for a rough ride! Programming EPDM addins is not for the faint hearted or those who don't like struggling with problems

                         

                         

                        Edit:

                         

                        Attached some !project files for your / someone else's use

                        It is setup for the 2013 version of EPDM, but it is forwards compatible based on the Edmlib reference that you add (C:\Program Files\SolidWorks Enterprise PDM\EPDM.Interop.epdm.dll)

                        So if your installed version of EPDM is 2014, then this reference that you add will make your addin compatible with 2014

                        Notes are included in the project files

                        Please move the files to the Visual Studio 2013 Express Project Templates folder (Tools -> Options -> Projects and Solutions -> General -> User Project templates)

                          • Re: Conditional Data card
                            James Guilford

                            Thanks for your help Andries Koorzen, Can't wait to face challenging problems ..I hope I get it working

                            • Re: Conditional Data card
                              James Guilford

                              Hello,

                               

                              Update: After so many tries I managed to Link excel to database. I also edited the above code to meet my needs, however I have ran into some problems and was wondering if you have had any experiences with it?

                               

                              1-When I execute the code I get an error ("A project with an output type of class library can not be started directly) . I did a Google search and advised me to right click on the project and set it as Executable project or start as new instance,but I still get the error? am I doing something wrong ?

                              2- When I import the add-in to EPDM, I get an error "Could not implement the module Implementing class - Class not registered" ?

                               

                               

                              Thanks.

                               

                               

                              James

                                • Re: Conditional Data card
                                  Andries Koorzen

                                  Hi James.

                                   

                                  Some important notes before continuing:

                                  • Get to know the EPDM API. This must always be your first port of call, because it contains all the information you need to create any and all EPDM applications / addins
                                  • It is available to opening the installation location of EPDM on any machine and searching for API_GB.chm
                                  • On my machine it is located under c:\Program Files\SolidWorks Enterprise PDM\API_GB.chm
                                  • Work through and get a basic understanding of the examples applications in the Stand-alone Applications / Add-in Applications sections, specifically referring to the VB.Net applications in my case
                                  • I have found VB.net to be the most well document / easiest to learn language for beginners. I know some people are about to throw their hands in the air on this one, and if you have someone to assist you and he / she chooses C++ / C#, then by all means go for it
                                  • Use www.stackoverflow.com for general programming questions, like what is a dictionary / list / object?

                                   

                                  For the first problem there is a 2-option answer:

                                   

                                  1. Work in a windows forms application, then as an addin

                                  2. Work on the project only as an addin

                                   

                                  1. Work in a windows forms application, then as an addin

                                  Change the application type to that of a windows forms application (WinForms). This will ensure that when you click the Run button (F5), that the program starts up with a traditional Windows Form as the main object that you are modifying (If it is a class library, then the hosting application needs to be started - Visual Studio Express' only limitation, but not a biggy)

                                  1. change project type.jpg

                                  Doing this will allow you to easily set the breakpoints in your code in order to debug the application (see image).

                                  Debugging refers to systematically stepping through the program code (F11) and also to see what the values of your variables are. With a WinForms app you can solve your application issues to within 95% of all issues. The rest you will have to test as an addin inside the EPDM framework (EPDM is a framework more than an application IMHO)

                                   

                                  First port of call: you need to call up the data card from EPDM using the IEdmCardView5 Interface, then check your results. A WinForms application allows you to show what a datacard for a particular filetype would look like (if you have no idea what I'm talking about, that's OK, I also started like that )

                                  breakpoint.jpg

                                  Once that is done, change the application type to addin. For your purposes, this option might not work as easily because you're trying to manipulate the lists on datacards, not the files in the vault. So to do that, change the application type back to Class Library, and the startup object to (None)

                                   

                                  startup type CL.jpg

                                   

                                  • Go to the EPDM administration tool
                                  • Right click Addins -> New
                                  • Select both the dll file that was compiled (when you hit the Run button) and the Interop.EdmLib.dll assembly (an assembly is another name for a library / *.dll file)
                                  • If all goes well, this should now show your addin in the addins list

                                   

                                  Pros: You can incrementally grow your knowledge of programming while doing the development. MUCH easier to debug

                                  Cons: You will have to migrate to an addin application (not a biggy) which is compatible with EPDM

                                   

                                  2. Work on the project only as an addin

                                   

                                  Choosing this path has its difficulties. The biggest hurdle is probably that you need to know what you're doing i.t.o coding before being able to tackle this one

                                   

                                  Steps:

                                  • Use a template to start the addin
                                  • Add the appropriate hooks
                                  • Compile the addin
                                  • add to the EPDM system
                                  • see the results of what it does / does not do
                                  • Crash explorer once or twice (x1000)
                                  • Tear your hair out
                                  • Make the changes
                                  • Rinse and repeat cycle

                                   

                                  Pros: Develop only once

                                  Cons: Much more difficult / time consuming to troubleshoot

                                   

                                  Useful code in VB to help you - writes info to a log file (just copy and paste at the end of your class, then call like this

                                   

                                  appendToLogFile("Preparing to get the contents from SQL")

                                   

                                      ''' <summary>

                                      ''' Append to the log file for the task

                                      ''' </summary>

                                      ''' <param name="contents"></param>

                                      ''' <remarks></remarks>

                                      Public Sub appendToLogFile(ByVal contents As String, Optional ByVal keepContents As Boolean = True)

                                          Dim fi As FileInfo

                                   

                                          Try

                                              fi = New FileInfo(<logFileDestination>)

                                              If fi.Length > 10000000 Then

                                                  Using mySWriter As New IO.StreamWriter(<logFileDestination>, False)

                                                      mySWriter.WriteLine("****************************CLEARED TO REDUCE THE SIZE****************************")

                                                      mySWriter.Flush()

                                                  End Using

                                              End If

                                          Catch ex As Exception

                                   

                                          End Try

                                   

                                          Using mySWriter As New IO.StreamWriter(<logFileDestination>, keepContents)

                                              mySWriter.WriteLine(Now.ToString("MM/dd HH:mm:ss ") & contents)

                                              mySWriter.Flush()

                                          End Using

                                      End Sub

                                   

                                   

                                  (for the second problem):

                                  If you would like me to check your addin for a code problem, send me a private message on the forums and we can chat so that I can get it to a point where it can be succesfully added to EPDM

                                  • Re: Conditional Data card
                                    Andries Koorzen

                                    Hi James. It seems I haven't fully answered your previous question:

                                     

                                    I'm going to try to not go into too many details, but basically this is what happens:

                                    When you get the message "Class not registered", it means that the assembly (your addin.dll + interop.edmlib.dll) files have not been fully registered in the computer's global assembly cache (GAC). This means that there was a problem with the registration of the addin, which means there's probably some problem with your code

                                     

                                    I'm attaching a working version of an addin which can be added to a vault

                                    Copy and paste your working code in the addin, readding the addin to the vault after copying and pasting each section

                                    When the addin no longer works correctly, you'll know which section of it has caused it to fail.

                                     

                                    Make sure that the GUID which is specified in the addin is a fresh one, this one has often caught me out

                                    You can generate a new one by clicking on Tools -> Create GUID, then copying and pasting over the current one. If another program uses the same GUID (Unlikely but possible since you might have added your own addin more than once)

                                     

                                    It is very difficulty to know why the registration of the addin failed without the actual code.

                                    My suggestion for you at this point is to take a working addin, then modifying that until it fails in the same way, and then please posting your findings here for the benefit of others

                                     

                                    Edit: Seeing as we need to constantly restart windows explorer whenever we're addin a new addin to EPDM, I actually wrote a program which closes the EPDM Administration interface, kills explorer, starts both again, and navigates to the current working folder I have. This is mainly for 2 reasons: I can't get the debug addins option to work in EPDM (after many many tries + virtually zero documentation on the usage thereof), + I'm saving time by writing my own  automation tools!

                                      • Re: Conditional Data card
                                        James Guilford

                                        Hi Andries,

                                         

                                        Thank you again for your help. I think I have made some progress. These are the steps I took.

                                         

                                        I checked the references folder and all the appropriate .dll files seem to be there.

                                        I Used you project, and copy pasted my code inside of it, then I changed .NET version to 2.0.

                                        I built the project and added .dll files from bin>debug directory to EPDM.

                                        It seems that the add-in is added to PDM, when I go through the card to change a variable which triggers the add-in. I get an error that access is denied.

                                        An attempt to solve this issue, I ran Visual studio express as Admin and built the project.

                                        PDM administrator was ran as admin, and add-in was added.

                                        I tried to set Debug to be on <ANY CPU> configuration, but could not locate it on Visual Studio Express. Not sure why it's not there.

                                         

                                        With all the above, I still got the same error.

                                         

                                        I'm probably doing something wrong here!!!

                                          • Re: Conditional Data card
                                            Andries Koorzen

                                            Hi James.

                                             

                                            The fact that you got the addin loaded in EPDM is 50% of the coding done!

                                             

                                            See the image for setting the AnyCPU setting:

                                            AnyCPU.jpg

                                            I would leave the .NET framework at 4.0 if you can, because it has more functions available and compatibilty for later versions are assured. .NET 2.0 is still very relevant, make no mistake, but 4.0 is currently the active framework being used for EPDM 2014 and later

                                             

                                            I have had a number of problems with 2.0 when compiling certain addins. Rule of thumb is: If it's working don't fix it.

                                             

                                            In my original project I included a sub routine called appendToLogFile. Use this in conjuction with a try / catch block to figure out where the error is. This is very useful when running the addin on other computers, since it allows you to retrieve the log file and open it with something simple like notepad. If you really want to go the extra mile, you can use the EventViewer in Windows to create a proper log file, but perhaps leave that till later till you're more comfortable with the whole programming in .Net thing

                                             

                                            trycatch.jpg

                                             

                                            I see you also sent me some pm's so I'll have a look at that shortly