AutoCAD VBA to AHK Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ktbjx
Posts: 71
Joined: 11 Jul 2015, 23:53

AutoCAD VBA to AHK

21 Mar 2018, 08:20

ok, so i have this idea. since i have been using AHK to manipulate my excel.
I want to do the same to manipulate AutoCAD
I found this AutoCad VBA online:

Code: Select all



Public Sub LineDetail()

Dim oSS As AcadSelectionSet

Dim oEntity As AcadEntity

Dim iFilterCode(0) As Integer

Dim vFilterValue(0) As Variant



  On Error Resume Next

  Application.ActiveDocument.SelectionSets("Lines").Delete

  On Error GoTo 0

  

  Set oSS = Application.ActiveDocument.SelectionSets.Add("Lines")

  iFilterCode(0) = 0: vFilterValue(0) = "Line"

  oSS.SelectOnScreen iFilterCode, vFilterValue

  If oSS.Count Then

    For Each oEntity In oSS

      Dim oLine As AcadLine

      Set oLine = oEntity

      With oLine

        MsgBox "StartPoint: " & .StartPoint(0) & ", " & .StartPoint(1) & ", " & .StartPoint(2) & vbCrLf & _

               "EndPoint  : " & .EndPoint(0) & ", " & .EndPoint(1) & ", " & .EndPoint(2)

      End With

    Next oEntity

  End If

End Sub
can anyone know how to translate that to AHK???


i found some tutorials here in our forum but its not complete. all i can do is the SendCommand.
i wanna learn how to get the coordinates of a LINE and put in in a Variable

HERE is the tutorial i searched about Calling Autocad COM...

All that make sense to me is this code

Code: Select all

global ACAD := ComObjActive("AutoCAD.Application")
and this code

Code: Select all

acad.activedocument.sendcommand("_move`n")

my problem is, how will i get the LINE coordinates? and that leads me to the VBA code for AutoCAD that i found..
IDK how to translate it, all i want is to get those LINE coordinates and put it to Variables, which, the VBA i found has!..
if i can figure that out, i can use those variables to manipulate on my Excel AHK program.
please help me?
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: AutoCAD VBA to AHK  Topic is solved

21 Mar 2018, 12:54

This is not an exact translation but this shows how to selection lines and then display the points for them.

Code: Select all

; get handle to active AutoCAD
acApp := ComObjActive("AutoCAD.Application")

; delete My_Lines selection set if it exist
try
	acApp.ActiveDocument.SelectionSets("My_Lines").Delete

; create a My_Lines selection set
acSet := acApp.ActiveDocument.SelectionSets.Add("My_Lines")

; create proper COM objects to use as parameters
cFilterType := ComObjArray( 2, 1)	; array of VT_I2 = 2  ; 16-bit signed int
cFilterData := ComObjArray( 12, 1)	; array of VT_VARIANT = 0xC  ; VARIANT  
cFilterType[0] := 0
cFilterData[0] := "Line"

; select objects on screen to include in My_Lines selection set
acSet.SelectOnScreen(cFilterType, cFilterData)

; loop though each object selected (assuming they are lines)
for acLine in acSet
{
	; get the point object for Start and End
	pntStart := acLine.StartPoint
	pntEnd := acLine.EndPoint
	; display all the point information
	MsgBox % "START`nX = " pntStart[0] "`tY = " pntStart[1] "`tZ = " pntStart[2] "`n`nEND`nX = " pntEnd[0] "`tY = " pntEnd[1] "`tZ = " pntEnd[2]
}
This does no error checking on the objects selected and if they are not lines it will probably fail with an error.

EDIT: Went ahead and looked up the data type information to create the proper parameters for SelectOnScreen to limit selection to Lines. Included now in code above.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
ktbjx
Posts: 71
Joined: 11 Jul 2015, 23:53

Re: AutoCAD VBA to AHK

22 Mar 2018, 02:18

FanaticGuru wrote:This is not an exact translation but this shows how to selection lines and then display the points for them.

Code: Select all

; get handle to active AutoCAD
acApp := ComObjActive("AutoCAD.Application")

; delete My_Lines selection set if it exist
try
	acApp.ActiveDocument.SelectionSets("My_Lines").Delete

; create a My_Lines selection set
acSet := acApp.ActiveDocument.SelectionSets.Add("My_Lines")

; create proper COM objects to use as parameters
cFilterType := ComObjArray( 2, 1)	; array of VT_I2 = 2  ; 16-bit signed int
cFilterData := ComObjArray( 12, 1)	; array of VT_VARIANT = 0xC  ; VARIANT  
cFilterType[0] := 0
cFilterData[0] := "Line"

; select objects on screen to include in My_Lines selection set
acSet.SelectOnScreen(cFilterType, cFilterData)

; loop though each object selected (assuming they are lines)
for acLine in acSet
{
	; get the point object for Start and End
	pntStart := acLine.StartPoint
	pntEnd := acLine.EndPoint
	; display all the point information
	MsgBox % "START`nX = " pntStart[0] "`tY = " pntStart[1] "`tZ = " pntStart[2] "`n`nEND`nX = " pntEnd[0] "`tY = " pntEnd[1] "`tZ = " pntEnd[2]
}
This does no error checking on the objects selected and if they are not lines it will probably fail with an error.

EDIT: Went ahead and looked up the data type information to create the proper parameters for SelectOnScreen to limit selection to Lines. Included now in code above.

FG

OMG!! FG!!!!! you're a monster! you have no idea how much this would help me! thank you so much!



i have a question...

Code: Select all

#Persistent
#SingleInstance, Force
#NoEnv
Hotkey, Rbutton, off

$f2::
KeyWait, F2
if toggle := !toggle {
Hotkey, Rbutton, On 

IfWinExist, AutoCAD
WinActivate
IfWinExist, Autodesk
WinActivate
ToolTip, ON
Sleep, 300
ToolTip	
}
else 
{
Hotkey, Rbutton, Off

IfWinExist, AutoCAD
WinActivate
IfWinExist, Autodesk
WinActivate
ToolTip, OFF
Sleep, 300
ToolTip	
}
Return



RButton::

; get handle to active AutoCAD
acApp := ComObjActive("AutoCAD.Application")

; delete My_Lines selection set if it exist
try
	acApp.ActiveDocument.SelectionSets("My_Lines").Delete

; create a My_Lines selection set
acSet := acApp.ActiveDocument.SelectionSets.Add("My_Lines")

	

; create proper COM objects to use as parameters
cFilterType := ComObjArray( 2, 1)	; array of VT_I2 = 2  ; 16-bit signed int
cFilterData := ComObjArray( 12, 1)	; array of VT_VARIANT = 0xC  ; VARIANT  
cFilterType[0] := 0
cFilterData[0] := "Line"

; select objects on screen to include in My_Lines selection set
acSet.SelectOnScreen(cFilterType, cFilterData)

; loop though each object selected (assuming they are lines)

for acLine in acSet
{
	; get the point object for Start and End
	pntStart := acLine.StartPoint
	pntEnd := acLine.EndPoint
	; display all the point information
	;MsgBox % "START`nX = " pntStart[0] "`tY = " pntStart[1] "`tZ = " pntStart[2] "`n`nEND`nX = " pntEnd[0] "`tY = " pntEnd[1] "`tZ = " pntEnd[2]

	StartX := Round(pntStart[0],4)
	StartY := Round(pntStart[1],4)
	StartZ := Round(pntStart[2],4)
	EndX := Round(pntEnd[0],4)
	EndY := Round(pntEnd[1],4)
	EndZ := Round(pntEnd[2],4)

	FileAppend, %StartX%`t%StartY%`t%StartZ%`t%EndX%`t%EndY%`t%EndZ%`n,%A_WorkingDir%\TEST.txt

}
ExitApp
Return
Is there a way to just right click 1 LINE???
i actually don't need to select all the LINES... i need to select them individually
and this

Code: Select all

acSet.SelectOnScreen(cFilterType, cFilterData)
i think is why i need to click on the line then press SPACE or ENTER.... (the process is long! RIGHT CLICK > LEFT CLICK on line > PRESS ENTER)
what i want to do is just hover the mouse on a line and just right click it...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Freddie, haomingchen1998, mikeyww, mmflume, scriptor2016, ShatterCoder and 92 guests