Jump to content


Script example



10 replies to this topic

#1 Gintaras

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 27 March 2012 - 07:31 AM

Hi,

Can someone give Java or Vb script example? And how to register script to nanocad?

#2 ISL

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 27 March 2012 - 10:00 AM

Hello Gintaras,

JS and VBS scripts can be run from within nanoCAD by JS and VBS commands.

Simple examples:

VBScript
' Create a Ray object in model space
Dim rayObj
Set rayObj = ThisDrawing.ModelSpace.AddRay("3,3,0", "1,3,0")

' Create a line object in model space
Dim lineObj
Set lineObj = ThisDrawing.ModelSpace.AddLine("0,0,0", "2,2,0")

' Create a circle object in model space
Dim circObj
Set circObj = ThisDrawing.ModelSpace.AddCircle("20,20,0", 3)

' Create an ellipse object in model space
Dim ellObj
Set ellObj = ThisDrawing.ModelSpace.AddEllipse("5,5,0", "10,20,0", 0.3)
msgbox("zoom all")

' ZoomAll
ThisDrawing.Utility.Prompt "Perform a ZoomAll"
ThisDrawing.Application.ZoomAll


JScript
var ent = new Array
var pt = new Array
try {
ThisDrawing.Utility.GetEntity(ent,pt,"Select an ent1")
ThisDrawing.Utility.Prompt(ent[0].EntityName + " at " + pt_toString(pt[0]));
}
catch (ex) {
ThisDrawing.Utility.Prompt("oops");
}

function pt_toString(pt)
{
var sp = new VBArray(ThisDrawing.Utility.CreateSafeArrayFromVector(pt))
return sp.toArray().toString();
}

More information on nanoCAD API can be found in the nanoCAD Developers' Club http://developer.nanocad.com.
Build your own nanoCAD. Visit the nanoCAD API Blog. Join the nanoCAD Developers' Club.

#3 Gintaras

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 27 March 2012 - 10:48 AM

I try these two scripts, but nothing happened....

#4 Gintaras

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 27 March 2012 - 12:13 PM

Hi,

Why Java and Vb scripts don`t work on english version of nanoCAD?

#5 ISL

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 27 March 2012 - 12:47 PM

JScripts and VBScripts definetely work in English version of nanoCAD.


It's very strange to hear that nothing happens, scripts can either work or end with an error.

Please provide us with a step by step report of your actions and a screenshot of your command line.
Build your own nanoCAD. Visit the nanoCAD API Blog. Join the nanoCAD Developers' Club.

#6 cean

    Member

  • Members
  • PipPip
  • 13 posts

Posted 04 April 2012 - 02:30 AM

cool. I like this. vbs works for me.

#7 global_cadserver@yahoo.com

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 20 April 2012 - 01:08 PM

I just installed the nanocad and run in demo mode. run the vbscript and javascripts from the above samples. nothing happen

#8 ISL

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 23 April 2012 - 12:13 PM

I've attached the scripts to avod copy/paste problems. JS and VBS commands require scripts to be in ANSI encoding, Unicode is not supported yet.

nanoCAD Eng 3.5 3.5.1880.1071, © 2012 Nanosoft

Command: filedia
FILEDIA <1>: 0

Command: vbs
Script file path: c:\MyScripts\zoom.vbs
Perform a ZoomAll

Command: js
Script file path: c:\MyScripts\GetEnt.js
1 found
AcDbEllipse at 8.217525248701036,21.901834795531684,0

Command: filedia
FILEDIA <0>: 1

Attached Files


Build your own nanoCAD. Visit the nanoCAD API Blog. Join the nanoCAD Developers' Club.

#9 joseluis

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 22 March 2013 - 11:43 PM

HI. I am new in nanocad. Thanks for the examples.

The vbs works for me OK in the Model tab (not in Layout).
The js requests info in the console. I don´t know what values should I enter for ent, I used values such 1 or 10 and the js runs into the catch. I tried also indexes of created entities. This is the console outputs.


Select an ent or [?/]: 10
Specify opposite corner: 20
0 found
oops

#10 ISL

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 25 March 2013 - 06:19 AM

Hi joseluis,

Please add a viewport to the layout where you are running zoom.vbs (switch to the layout, View->Viewports->1 Viewport), and zoom will work as designed.

Regarding GetEnt.js, please pick an entity instead of entering number:

Select an ent or [?/]: <pick the ellipse created by zoom.vbs>
1 found
AcDbEllipse at 5.550731437335969,17.826057121504846,0

Build your own nanoCAD. Visit the nanoCAD API Blog. Join the nanoCAD Developers' Club.

#11 bllinky

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 13 July 2014 - 12:32 PM

Hello
Me need vbs to insert block. Pleas help!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users