Skip to content

Instantly share code, notes, and snippets.

@tmplinshi
Created October 5, 2017 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmplinshi/d79b629add37fcee9f36e11ba6a98f45 to your computer and use it in GitHub Desktop.
Save tmplinshi/d79b629add37fcee9f36e11ba6a98f45 to your computer and use it in GitHub Desktop.
#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._))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment