MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: how to use vb.net/netlink to export a dxf file

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101848] Re: [mg101747] how to use vb.net/netlink to export a dxf file
  • From: Todd Gayley <tgayley at wolfram.com>
  • Date: Sun, 19 Jul 2009 07:15:21 -0400 (EDT)
  • References: <200907161217.IAA02321@smc.vnet.net>

At 07:17 AM 7/16/2009, jonk wrote:
>I am trying to write a vb.net program that connects to Mathematica,
>performs some computation that results in a curve and exports that
>curve as a dxf file. I thought the code below would work as I modified
>some code I found on this site (discussion: how to save a mathematica-
>made imagebox.image as jpg, gif, bmp in c#/.netlink? )
>
>any help would be greatly appreciated. I am new to mathematica so in
>case it helps to understand why I am trying to do this. I am an
>architect using a 3d parametric modeling program that can execute
>vb.net programs. the idea is to extend the program by using
>mathematica to generate more complex curves. It could be especially
>useful now that mathematica can export NURBS curves and surfaces. Very
>exciting. Thanks again.
>
>' This launches the Mathematica kernel:
>     Dim ml As IKernelLink = MathLinkFactory.CreateKernelLink()
>
>     ml.Evaluate("SetDirectory[\""C:/Documents And Settings/User/
>Desktop/\""]")
>     ml.WaitForAnswer()
>
>     ml.Evaluate("gr = Plot[ Sin[x], {x, 0, 2*Pi}]")
>     ml.Evaluate("Export[\""testMATH.dxf\"",gr, \""DXF\""]")
>     ml.Close()


There are a couple problems with this program. The main reason for 
failure is the incorrect syntax for embedded " chars in VB strings. 
Instead of using a \ to quote " chars in a string, VB uses two 
consecutive " chars. The other problem is that you always need to 
read or discard the result from every computation. Here is a fixed 
version of your program:

      Dim ml As IKernelLink = MathLinkFactory.CreateKernelLink()
      ml.WaitAndDiscardAnswer()  ' Discards initial packet containing "In[1]:="

      ml.Evaluate("SetDirectory[""C:/temp/""]")
      ml.WaitAndDiscardAnswer()

      ml.Evaluate("gr = Plot[ Sin[x], {x, 0, 2*Pi}]")
      ml.WaitAndDiscardAnswer()

      ml.Evaluate("Export[""testMATH.dxf"",gr, ""DXF""]")
      ml.WaitAndDiscardAnswer()

      ml.Close()


Todd Gayley
Wolfram Research 



  • Prev by Date: Re: Determine if a parameter is a function
  • Next by Date: Re: Standard deviations and Confidence intervals with respect to
  • Previous by thread: how to use vb.net/netlink to export a dxf file
  • Next by thread: Re: how to use vb.net/netlink to export a dxf file