Quantcast
Channel: Mentor Graphics Communities: Message List
Viewing all articles
Browse latest Browse all 4541

Re: How to iterate through component via .NET(such as C#, in DxD or XDx)

$
0
0

The following is for XDx:

 

1. Add a COM reference to viewdraw in your project.

2. Add a module to your project.  Declare the following global variables in it:

     Public app as ViewDraw.Application

     Public doc AsObject

     Public dxd_running AsBoolean

     Public prog_id AsInteger

     Public proceed AsBoolean

     Public scomps AsObject

     Public scomp As ViewDraw.Component

     Public design_name As String

 

2.1. At the top of the module, add the following import statement:

     Imports Microsoft.Win32

 

 

3. Also in that module, add the following:

 

PublicSub DX_Connect()

         dxd_running = false

         app = Nothing

         onerrorgoto dxd_error

         app = GetObject(,"ViewDraw.Application" & "." & prog_id.ToString)

         doc = app.ActiveDocument

         dxd_running = True

 

        

         ExitSub

         dxd_error:

         msgbox("Error: No active DxDesigner Application found.")

        

     EndSub

    

     PublicSub get_ver()

         Dim regkey As RegistryKey

         Dim tmp AsString

        

         regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Classes\MGCPCB.ExpeditionPCBApplication\CurVer", False)

        

         If regKey IsNothingThen

             tmp = "Critical registry keys are missing.  This most likely means that the Mentor Graphics "

             tmp = tmp & "tools have not been installed properly." & vbCrLf & vbCrLf

             tmp = tmp & "Try to correct that then start over. "

             MsgBox(tmp)

             proceed = false

             exitsub

         EndIf

        

         tmp = regkey.GetValue("")

         tmp = tmp.Substring(InStrRev(tmp, "."))

         prog_id = CInt(tmp)

        

         regKey.Close()

     EndSub

 

4. In whatever subroutine runs when you load the main form (usually something like Main_FormLoad), add the following code:

 

        proceed = True

         get_ver()

        

         if proceed = falsethen

             me.close

         endif

         DX_Connect()

 

5. In whatever subroutine you have the action taking place, add the following to get all design components and iterate through them:

 

          'load all components into scomps.  scomps will get a reference to every component in the design

         design_name = app.GetProjectData.GetiCDBDesignRootBlock(app.GetActiveDesign())

         scomps = nothing

         scomps = app.DesignComponents("", design_name, "-1", , False)    'gets all the components in the design

        

         'cycle through all the components and get the info needed for the bom

         ForEach scomp In scomps

                    'do something on each component

         Next

--------------------------------------------------------------------

There is another way to do it, which is to iterate through all the sheets, and then use the query function to select components on each sheet, then iterate through them.  I have some examples of how to do that also, if you want to do it that way.  It involves a lot more overhead because of opening all the sheets and displaying them on the screen, but in some cases that's a preferred method to doing it all behind the scenes like the method I've shown here.

 

hope this helps.  It should get you on your way.  If you have more questions, please do not hesitate to ask.


Viewing all articles
Browse latest Browse all 4541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>