Help with syntax: Object.GetVariables(Var1, Var2) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
anbraLT
Posts: 16
Joined: 25 Sep 2017, 01:14

Help with syntax: Object.GetVariables(Var1, Var2)

25 Sep 2017, 02:10

Basicly I need to get Object information by sending 1 variable/or no variable to function in AutoCAD though COM.
Was searching forums for hours(around 5, yes im desperate :headwall: ), and im stuck on syntax, dunno if this is even possible.
Short Function description Im trying to use:
object.GetXData AppName, XDataType, XDataValue
Where, GetXData - my fuction call/method I guess...
AppName - String input I need to send. Can send no input to Get all data. Then I recive array of all XDataType, XDataValue
XDataType, XDataValue - variables I need recive/see.

AutoCAD descrition of function if needed:
http://help.autodesk.com/view/ACD/2015/ ... 15B6B98426

How my syntax should look, so I could "see" XDataType, XDataValue ?

Tried:
variable := object.GetXData("AppNameRandomString", XDataType, XDataValue)
MsgBox % XDataType XDataType[1] XDataType[1,1] XDataType[1][1] ; nothing

How does AHK knows, what variable in brackets () we send and which one we recive/read ?
AutoCAD doesn't give error if im calling with such syntax, though removing one of items in brackets starts giving error.

If id need to recive 1 variable.
Var := Object.Function
or
Object.Function(var)
works
So in theory, to recive 2 variables.
Object.Function(var1, var2) should work. Though I cant read values ( how do I know If I even get them ? )
Also I cannot use simpler function, where I do not need to "send" any parameters:
object.GetBoundingBox MinPoint, MaxPoint
Written in AHK should look like:
object.GetBoundingBox(MinPoint, MaxPoint)
MsgBox % MinPoint MinPoint[0] MinPoint[0, 1] MinPoint[0][1] ; doesn't give me anything.
MinPoint, MaxPoint - should be arrays.

As writing this post I got idea, for syntax, which work on some other cases.
If XDataType is array. need to write something like this :
variable := object.GetXData("AppNameRandomString", XDataType, XDataValue)
For Object/item in XDataType
MsgBox % XDataType[1]

Ok, this, didnt worked...

Please. Any help appreciated :)

Best Regards,
Anbra
anbraLT
Posts: 16
Joined: 25 Sep 2017, 01:14

Re: Help with syntax: Object.GetVariables(Var1, Var2)

25 Sep 2017, 07:52

Basicly BUMP

That should be easy for ppl with COM knowledge, how to read 2 parameters of object function ?...
object.GetMeVariable(SomethingIWantToSee1,SomethingIWantToSee2) ; how the syntax should look to read 2 values by calling once to program, or twice, as long as I get booth variables?...
MsgBox % SomethingIWantToSee1 ; .... ???
anbraLT
Posts: 16
Joined: 25 Sep 2017, 01:14

Re: Help with syntax: Object.GetVariables(Var1, Var2)

25 Sep 2017, 23:04

BUMP :headwall: BUMP :headwall: BUMP :headwall:
At least, anyone can confirm that syntax is correct here ?
Object.GetVariables(Var1, Var2)
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Help with syntax: Object.GetVariables(Var1, Var2)

25 Sep 2017, 23:29

variable := object.GetXData("AppNameRandomString", XDataType, XDataValue)
The syntax seems correct. However I wonder if you just using the object from nowhere. The object should created by ComObjCreate or ComObjActive.
anbraLT
Posts: 16
Joined: 25 Sep 2017, 01:14

Re: Help with syntax: Object.GetVariables(Var1, Var2)

26 Sep 2017, 01:01

Yes, I create AutoCAD object, ComObjActive("AutoCAD.Application")
And everything is fine, I made "a lot" scripts though COM for autocad, just got stuck on the syntax.

object.Coordinate(ArrayOfXYZ) - I can see coordinates in array

But, why this doesn't give any answers.
object.GetBoundingBox(MinPoint, MaxPoint)
MsgBox % MinPoint MinPoint[0] MinPoint[0, 1] MinPoint[0][1] ; doesn't give me anything.
MinPoint should give same 3 coordinates XYZ as object.Coordinate(ArrayOfXYZ), the difference is object.GetBoundingBox calls back two coordinates, start and end of box.
Strange. So in theory, you confirm syntax is okay. thus I need to find a way how to "decode" the variable I get.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Help with syntax: Object.GetVariables(Var1, Var2)

26 Sep 2017, 01:42

Try:

Code: Select all

MinPoint := ComObjArray(VT_VARIANT:=12, 3)
MinPoint := ComObjArray(VT_VARIANT:=12, 3)

object.GetBoundingBox(ComObjValue(MinPoint), ComObjValue(MaxPoint))
MsgBox, % MinPoint[0] "," MinPoint[1] ","  MinPoint[2]
anbraLT
Posts: 16
Joined: 25 Sep 2017, 01:14

Re: Help with syntax: Object.GetVariables(Var1, Var2)

26 Sep 2017, 02:13

Now we talking :)
Thanks man !
Will try this as soon as I can.

can you further explain what "VT_VARIANT:=12" stands for ? 3 is for the array "size", 3 coordinates. but 12 ?

Also, why is it so if I use object.Coordinates(VariablesArray), I do not need to create extra ComObjArray to read values in VariablesArray, while if I use call for "multiple" arrays I need this ? Or this might be, that AutoCAD gives those arrays as COM objects, instead simple arrays, maybe that's the case I cant see values.

Anyways, ill update this post if I succeed/fail using Your method.
Thanks once again
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Help with syntax: Object.GetVariables(Var1, Var2)

26 Sep 2017, 02:37

ComObjArray() needs to know the base type of the array for that you need to use one from the subset of the variant type codes in this case VT_VARIANT aka 12

you can also try other combinations for the type SafeArray := ComObjArray(Type := (VT_VARIANT:=0xC) | (VT_ARRAY := 0x2000), 3)
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
anbraLT
Posts: 16
Joined: 25 Sep 2017, 01:14

Re: Help with syntax: Object.GetVariables(Var1, Var2)

26 Sep 2017, 03:13

MinPoint := ComObjArray(Type := (VT_VARIANT:=0xC) | (VT_ARRAY := 0x2000), 3)
MaxPoint := ComObjArray(VT_VARIANT:=12, 3)
object.GetBoundingBox(ComObjValue(MinPoint), ComObjValue(MaxPoint))
MsgBox, % MinPoint "," MinPoint[0] "," MinPoint[1] "," MinPoint[2] "," MaxPoint "," MaxPoint[2]

This gave me nothing. Any more ideas ?... :/

AutoCAD gives no errors, thus meaning, that we call to object.GetBoundingBox correctly with 2 "variables" though... what are in those variables, or even if we can read them... dunno...
As mentioned before, if its 1 variable array, I don't need to make safearray or new COM objects.
But im willing to try any given ideas, as this drives me crazy, not figuring out whats wrong with this, as in theory everything seems legit.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Help with syntax: Object.GetVariables(Var1, Var2)  Topic is solved

05 Oct 2017, 11:54

I got hope by seeing this answer, install AutoCAD again and finally figured out: :)

Code: Select all

#NoEnv

cad := ComObjActive("AutoCAD.Application")

; AddText
point := Point3d("789.72", "1500.45", "0.0")
textObj := cad.ActiveDocument.ModelSpace.AddText("AutoHotkey", point, 80.77)
textObj.Update

; AddLine
point1 := Point3d("489.72", "1913.45", "0.0")
point2 := Point3d("1069.86", "2180.80", "0.0")
lineObj := cad.ActiveDocument.ModelSpace.AddLine(point1, point2)
lineObj.Update

; GetBoundingBox
minExt := ComVar()
maxExt := ComVar()
lineObj.GetBoundingBox(minExt.ref, maxExt.ref)
MsgBox, % minExt[][0] "," minExt[][1] "," minExt[][2] "`n"
        . maxExt[][0] "," maxExt[][1] "," maxExt[][2]

; SetXData
XDataType := VarArrayCreate(VT_I2 := 2, "1001", "1000", "1003", "1041")
XDataValue := VarArrayCreate(VT_VARIANT := 0xC, "Test_Application", "This is a test for xdata", "0", "1237324938")
lineObj.SetXData(XDataType, XDataValue)

; GetXData
XDataType := ComVar()
XDataValue := ComVar()
lineObj.GetXData("", XDataType.ref, XDataValue.ref)
MsgBox, % XDataType[].MaxIndex() "`n" XDataType[][0] "`n" XDataType[][1] "`n" XDataType[][2] "`n" XDataType[][3] "`n"
        . "-----------------------------`n"
        . XDataValue[].MaxIndex() "`n" XDataValue[][0] "`n" XDataValue[][1] "`n" XDataValue[][2] "`n" XDataValue[][3]

; Delete
; lineObj.Delete
; cad.Application.Update

;----------------------------------------------------------
Point3d(d1, d2, d3)
{
	pt := ComObjArray(5, 3) ; VT_R8 = 5
	pt[0] := d1
	pt[1] := d2
	pt[2] := d3
	return pt
}

VarArrayCreate(Type=0xC, Values*)
{
	arr := ComObjArray(Type, Values.MaxIndex())
	for i, v in Values
		arr[i-1] := v
	return arr
}

; https://autohotkey.com/docs/commands/ComObjActive.htm#Examples 
;
; ComVar: Creates an object which can be used to pass a value ByRef.
;   ComVar[] retrieves the value.
;   ComVar[] := Val sets the value.
;   ComVar.ref retrieves a ByRef object for passing to a COM function.
ComVar(Type=0xC)
{
	static base := { __Get: "ComVarGet", __Set: "ComVarSet", __Delete: "ComVarDel" }
	; Create an array of 1 VARIANT.  This method allows built-in code to take
	; care of all conversions between VARIANT and AutoHotkey internal types.
	arr := ComObjArray(Type, 1)
	; Lock the array and retrieve a pointer to the VARIANT.
	DllCall("oleaut32\SafeArrayAccessData", "ptr", ComObjValue(arr), "ptr*", arr_data)
	; Store the array and an object which can be used to pass the VARIANT ByRef.
	return { ref: ComObject(0x4000|Type, arr_data), _: arr, base: base }
}

ComVarGet(cv, p*) { ; Called when script accesses an unknown field.
	if p.MaxIndex() = "" ; No name/parameters, i.e. cv[]
		return cv._[0]
}

ComVarSet(cv, v, p*) { ; Called when script sets an unknown field.
	if p.MaxIndex() = "" ; No name/parameters, i.e. cv[]:=v
		return cv._[0] := v
}

ComVarDel(cv) { ; Called when the object is being freed.
	; This must be done to allow the internal array to be freed.
	DllCall("oleaut32\SafeArrayUnaccessData", "ptr", ComObjValue(cv._))
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, RickC and 143 guests