10 Replies Latest reply on May 10, 2016 1:17 AM by broesel

    Automation using C or C++

    wayne

      Is anyone using c or c++ for automation? It would be nice to see some examples of accessing the database.

       

      Thanks!

        • 1. Re: Automation using C or C++
          dirk_from_munich

          I've used an Excel based tool, that connects to an open PCB and reads all components. Later on, I tried to use Visual Studio Express 2008 C++, but I couldn't connect to the PCB (I don't know, how to use the COM object properly). So it would be interesting for me, too.

           

          How can C++ connect to the PCB, how can the license be checked and how can a collection of components, nets, etc. be read? A very short template would help a lot.

           

          I know, that Mentor wrote

           

          There are no samples for the C++ programming language. You can use several languages to write your scripts. If the language supports COM object models you can use it with the automation server.

           

          in the PCB Automation Reference, but I believe, that there is anyone outside, who already has written an automation program with C or C++.

          • 2. Re: Automation using C or C++
            yu.yanfeng

            Yes. We used C++

            Yanfeng

            • 3. Re: Automation using C or C++
              wayne

              Glad to hear that someone is using c++ with automation. Do you have any samples you could put up for examples?

              • 4. Re: Automation using C or C++
                misael.perez.martinez

                I'm not sure about C/C++, but this is what it looks like in python for WinXP:

                 

                #Create DxDesigner com client
                ViewDrawApp = win32com.client.Dispatch('ViewDraw.Application')

                 

                After that you can start accessing the objects inside DxDesigner. For example:

                 

                PageBlock = ViewDrawApp.ActiveView.Block

                #Get block corner points
                BlockLowerLeftX = PageBlock.GetBboxPoint(VDLOWERLEFT).X
                BlockLowerLeftY = PageBlock.GetBboxPoint(VDLOWERLEFT).Y
                BlockUpperRightX = PageBlock.GetBboxPoint(VDUPPERRIGHT).X
                BlockUpperRightY = PageBlock.GetBboxPoint(VDUPPERRIGHT).Y

                 

                I'm sure there must be an equivalent method for C/C++.

                 

                -- Misael

                • 5. Re: Automation using C or C++
                  wayne

                  Bumping this up!

                   

                  I'm just looking for an example of accessing expedition and making a simple collection object. If I get that much, it should be enought to get me started, I hope.

                   

                  Examples anybody??

                  • 6. Re: Automation using C or C++
                    a.gieger

                    We are using Visual Basic 2008 Express and I can give you a short example how to do this in Basic. You should be able to convert into C or C++.

                     

                            Dim objPCBApp As MGCPCB.Application

                            Dim objPCBDoc As MGCPCB.Document

                     

                            Try

                                ' Try to get the application object Expedition

                                objPCBApp = GetObject(, "MGCPCB.ExpeditionPCBApplication")

                            Catch ex As Exception

                            End Try

                     

                            objPCBDoc = objPCBApp.ActiveDocument

                     

                    Best Regards

                    Andreas

                    • 7. Re: Automation using C or C++
                      broesel

                      Hi,

                      because C and C++ are unmanaged UNIX-based compilers, it is very different and complicated to convert a COM interface from VB or C# into C++.

                      I want to create C++ program with Viewdraw.Application as well. It took me days of trying and investigating until I got a little program.

                       

                      If it is helpful for you to see how it is generally working, please tell me how to upload the project as a ZIP file.

                      I am new in this community and cannot find an upload buttom.

                       

                      But I got a serious problem casting a IVdObjs list into a single IVdComp object.

                      Can anybody help me, what is wrong in my code?

                      Everything else is working.

                       

                               if (!SUCCEEDED (objects->get_Count (&objCnt)))

                                  continue;

                       

                               for (int objIdx = 1; objIdx <= objCnt; objIdx++) {

                                  // The objects seems to be okay, because this works:

                                  VdObjectType objType;

                                  objects->GetType (objIdx, &objType);

                                  _tprintf (_T("DBG: objType = '%d'\n"), (int)objType);

                       

                                  // To get the comp object seems to work:

                                  CComPtr<IVdComp> comp = NULL;

                                  if (SUCCEEDED (objects->Item (objIdx, (IDispatch**)&comp))) {

                       

                                     // But all methods with this objects fail, like this:

                                     int id = 0;

                                     comp->get_Id (&id);

                                  }

                               }

                       

                      PS: How can I change the font of the source code in this window?

                       

                      Bye

                      Brösel

                      1 of 1 people found this helpful
                      • 8. Re: Automation using C or C++
                        keithp

                        Hello Brösel,

                         

                        I am also new to using this community; but have a keen interest in figuring out how to port an extensive collection of applications and scripts from VB.Net and VBS to C++ and run them in-process with DxDesigner (hoping for a large performance increase). I would assume that the process would be similar to the solution would be similar to that used with Pads or Expedition, but don't yet know enough C++ to really get started on the port.

                         

                        When replying to a post, look for a link in the top right corner of the 'reply' text box for a link labeled "Use advanced editor" which will expose more controls.

                        Paste your code into the text edit box first, select the entire code block, then look for a double right arrow icon ">>" in the editor controls, select "Syntax Highlighting", then the code type (or Plain) and you will get a code block. I've found the Syntax Highlighting to be a bit buggy which is why I paste->select first, it seems to work better.

                         

                        The advanced editor also exposes the Attach link at the bottom right.

                         

                        Not sure if this will help you (using C++) with your question regarding IVdComp objects or not; but this is how I do it with VB.Net. Create a collection of objects then iterate through the collection until you find the object you want... a slow process if you have a large number of objects.

                         

                                Dim compObjs As ViewDraw.IVdObjs
                                Dim compObj As ViewDraw.Component
                        
                                compObjs = app.DesignComponents(design.LibName, design.Name, -1, "", False)
                        
                                Dim c As Integer = 1
                                For c = 1 To compObjs.Count
                                    compObj = compObjs.Item(c)
                                Next
                        

                         

                        Regards,

                        Keith

                        • 9. Re: Automation using C or C++
                          keithp

                          Obviously, I didn't proof read my post very well before submitting it... I meant to write:

                           

                          I would assume that the process or solution would be similar to that used with Pads or Expedition, but don't yet know enough C++ to really get started on the port.
                          • 10. Re: Automation using C or C++
                            broesel

                            Hi Keith,

                             

                            Sorry for the late answer, I was in vacation.

                            Thank you for your hints.

                            Unfortunately the code is not helpful, because I already wrote the program in VBS, VB and in C#.

                            Everything works, but C++.

                             

                            Please find my little C++ project attached.

                            It works until I try to access the IVdComp object.

                            At least you can use it as a template for other Viewdraw programs.

                            Possibly you get my problem fixed, that would be great.

                             

                            Ciao, Brösel