5 Replies Latest reply on Nov 29, 2017 7:06 AM by Patrick.Cashman

    Visual Studio (or any other 3rd party Automation Client, not supported by Mentor)

    peter_festesen

      Knowing that quite many of the subscribers in this community use Visual Studio or other 3rd party automation clients – well knowing that these are not officially supported by Mentor Support.

      Just to clarify, the Automation Server is DxDesigner (viewdraw.exe), the External Automation Client is the compiled .exe from Visual Studio. For completeness, an internal client would be a vbs or efm file, run from inside DxDesigner Application

       

      How do you normally work around this situation?  I am using the Addline2 method for DxDesigner Automation as an example :

      Using the Addline2 method in an internal client works, but when running with the external client, the call

       

      Set DxDesignerLine = Activeview.Block.AddLine2(1,1,x*10,y*10)

       

      sometimes returns ‘Nothing’ , where is should return the DxDesignerLine object. This apparently is worse when the DxDesigner Application is kept open during script runtime, so there must be some disturbance happening.

       

      Q1: Can someone explain why this happens ?

       

      Q2: Can someone suggest a workaround for this issue ?

        • 1. Re: Visual Studio (or any other 3rd party Automation Client, not supported by Mentor)
          Patrick.Cashman

          I made an example script in my Visual Studio test project:

           

          Sub add_line()

                  

                   Dim view As ViewDraw.View

                   Dim blok As ViewDraw.Block

                   Dim x1, y1, x2, y2 As Double

                   Dim line As ViewDraw.Line

           

                   view = app.ActiveView

                   blok = view.Block

                  

                   x1 = 100

                   y1 = 100

                  

                   x2 = 200

                   y2 = 200

                  

                   line = blok.AddLine2(x1, y1, x2, y2)

          End Sub

           

          It works as expected and draws a line on the open schematic sheet.  The DxD application remains open. Of  course the global app variable is set by a method that connects to the open DxD session.

           

          Other than the Set statement you have in your command which is not needed in vb.net, I don't see any reason the command you posted will not work.

          • 2. Re: Visual Studio (or any other 3rd party Automation Client, not supported by Mentor)
            peter_festesen

            Thanks, Patrick

            Just to clarify - the issue at hand is that the Addline2 method sometimes (as in 20 times of 1000) fails to return the Line object and returns 'Nothing' as the object. 

            This never happens with internal clients, but appears to happen when using dotNet as the external client. 

            • 3. Re: Visual Studio (or any other 3rd party Automation Client, not supported by Mentor)
              Patrick.Cashman

              In that case I'd wrap the command in little loop something like this:

               

              line = nothing

              n = 0

              While line is nothing

                   line = blok.AddLine2(x1, y1, x2, y2)

                   n = n + 1

                   if n  = 5 then Exit While

              End While

               

              If line is nothing then

                   Msgbox("No line created from " & x1 & "," & y1 & " to " & x2 & "," y2)

                   'or some other notification

              End If

               

              That will give you up to 5 chances to create the line.  Perhaps you could write the coordinates to a file and then come back and attempt to draw them again later with the text file data.

              • 4. Re: Visual Studio (or any other 3rd party Automation Client, not supported by Mentor)
                peter_festesen

                Thanks for the workaround - I like it !!!!

                I have learned two other important things in the meantime. This is directly related to the Addline2 example, and may not be valid for all.

                 

                Make the application invisible - it greatly reduces the number of 'Nothing' occurences.

                 

                app.Visible = False

                 

                'Do your Stuff

                 

                app.Visible = True

                 

                Another method makes use of  the SetRedraw method, so in line with the above

                 

                app.SetRedraw(False)

                 

                'Do your Stuff

                 

                app.SetRedraw(True)

                 

                app.Visble will hide the DxDEsigner application (think Minimize), so make sure you tell the user that it is about to happen, in order not to scare them. The use of app.Visble will also shorten your runtime

                 

                app.SetRedraw will simply refrain from updating the graphics window in DxDesigner. Ther is only little runtime improvement to be gained by using SetRedraw.

                • 5. Re: Visual Studio (or any other 3rd party Automation Client, not supported by Mentor)
                  Patrick.Cashman

                  You're welcome.  Whenever creating an object, you can't be too careful to make sure it actually happened, so my code is full of error traps like that.

                   

                  Thanks for the info on app.visible and app.setredraw.  Both appear to be useful.