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?