1

I'm try to translate a VBAmacro working in autoCAD to VBscript to work with nanoCAD.
And step by step i move line from VBAmacro to VBscript and see if everything is working so...
I check every entity in ModelSpace

For c = 0 To ThisDrawing.ModelSpace.Count - 1

if is a "AcDbBlockReference" then I check if it has HasAttributes

   If (ent.ObjectName = "AcDbBlockReference") Then
          Set ObjRef = ThisDrawing.ModelSpace.Item(c)
          If ObjRef.HasAttributes Then

till here works good but when I want to know the position of this "AcDbBlockReference" by

ThisDrawing.Utility.Prompt ObjRef.InsertionPoint(0)

I have an error.....
Then I go on google and found this page
Using TypeLib Information Objects from tlbinf32.dll it is possible to list all members of a class.
and what???

  AcDbBlockReferenceObject IAcadBlockReference
  Sub QueryInterface(riid, ppvObj)
  Function Unknown Type 19 AddRef()
  Function Unknown Type 19 Release()
  Sub GetTypeInfoCount(pctinfo)
  Sub GetTypeInfo(itinfo, lcid, pptinfo)
  Sub GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid)
  Sub Invoke(dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr)
  Property (set/get) Handle
  Property (set/get) ObjectName
  Sub GetXData(AppName, XDataType, XDataValue)
  Sub SetXData(XDataType, XDataValue)
  Sub Delete()
  Property (set/get) ObjectID
  Property (set/get) Application
  Property (set/get) Database
  Property (set/get) HasExtensionDictionary
  Function vbEmpty GetExtensionDictionary()
  ...
  ...
  Property (set/get) color
  Property (set ref/get) color
  Property (set/get) InsertionPoint     <==============
  Property (set ref/get) InsertionPoint <==============
  Property (set/get) Name
  ...

One of the Property is (set/get) InsertionPoint so why I have an error?
Then I try with this code:

Set Obj = ThisDrawing.ModelSpace.Item(0)
ThisDrawing.Utility.Prompt Obj.ObjectName
if (IsArray(Obj.InsertionPoint)) then
    ThisDrawing.Utility.Prompt "IsArray" 
    ThisDrawing.Utility.Prompt ubound(Obj.InsertionPoint)
else
    ThisDrawing.Utility.Prompt "NOT Array" 
end if 

and the response is:
Obj.ObjectName is a AcDbBlockReference
IsArray is true
ubound = 2

so how can I take the value of Obj.InsertionPoint(0) and Obj.InsertionPoint(1) if this generate an error?
---------------------------------------------------------------------------
ADD1
If I use this code:

dim Obj
Set Obj = ThisDrawing.ModelSpace.Item(0)
ThisDrawing.Utility.Prompt "Obj.ObjectName: " & Obj.ObjectName
ThisDrawing.Utility.Prompt "isArray()     : " & isArray(Obj.InsertionPoint)
ThisDrawing.Utility.Prompt "lbound        : " & lbound(Obj.InsertionPoint)
ThisDrawing.Utility.Prompt "ubound        : " & ubound(Obj.InsertionPoint)
ThisDrawing.Utility.Prompt Obj.InsertionPoint(0)

the result is
Obj.ObjectName: AcDbBlockReference
isArray() : TRUE
lbound : 0
ubound : 2
err: "Errore di run-time di Microsoft VBScript" raised an exception "L'oggetto non è un insieme: 'InsertionPoint'" at line 9 pos 0 ThisDrawing.Utility.Prompt Obj.InsertionPoint(0)

and if I try to move the blockrference by create a new point

dim pnt(3)
pnt(0) = 100
pnt(1) = 1000
pnt(2) = 0
Obj.InsertionPoint = pnt

the Obj (blockreference) move from actual position to pnt
---------------------------------------------------------------------------
ADD2
I found this script in javascript

try {
    ThisDrawing.Utility.Prompt(ThisDrawing.ModelSpace(0).EntityName);
    ThisDrawing.Utility.Prompt(pt_toString(ThisDrawing.ModelSpace(0).insertionPoint));
}
catch (ex) {
    ThisDrawing.Utility.Prompt("oops");
}

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

and the result is:
AcDbBlockReference
267.9 , 2122.5 , 0
So actually I can konw insertionPoint in js but not in vbscript why???
Is it possible to translate this js code to vbscript?

  • 1
    *"I have an error....."* What is the error? – Lee Mac Mar 16 '19 at 18:09
  • VBScript doesn't use type libraries. – Noodles Mar 16 '19 at 18:49
  • "VBScript doesn't use type libraries." what do you mean? – tracciatura.net Mar 17 '19 at 17:57
  • It doesn't use type libraries. It uses `CreateObJect`/`GetObject` which uses IDispatch. IDispath also knows as late binding is a conversation. "Hello object do you have a method/property called `TrueColor`". Object replies "I do and it is command number 7", "Ok please do command 7". With Early binding (`set x = New Object`) the command number is in the type library and you program knows to go to the 7th address in the VTable. One major difference is constants declared in the type library are not available. You have to type them yourself (`const x = 10`. – Noodles Mar 20 '19 at 01:28
  • Ok but how can I solve my problem? As you can see in add information I can Move the object in CAD by assign a new point `Obj.InsertionPoint = pnt` but I can't know the actually InsertionPoint why? Is because InsertionPoint is an array? – tracciatura.net Mar 21 '19 at 09:03

1 Answers1

0

THE SOLUTION

Dim pnt
pnt = ThisDrawing.Utility.CreateSafeArrayFromVector(Obj1.InsertionPoint)

ThisDrawing.Utility.Prompt pnt(0) 
ThisDrawing.Utility.Prompt pnt(1) 
ThisDrawing.Utility.Prompt pnt(2)

thanks for all