lorenkinzel Posted April 26, 2015 Share Posted April 26, 2015 (edited) This is tailored toward drawing wood-framing components in walls. A bit easier to learn than Turbo-cad & considerably cheaper.Dimensioning is set to inches/decimal inches. Apologies to those who have moved-on from feet/inches.Edit: It is done using the Excel drawing object (you need to open Excel to use it). Edit: added ability to switch between inch-decimal & feet-inch-fractionexpandcollapse popup;OPEN THE EXCEL BOOK FIRST - AS IN BEFORE YOU OPEN THE SCRIPT #cs AutoIt Version: 3.3.9.22 (Beta) Author: Loren Kinzel Script Function: Emulation of autocad. Specifically tailored toward drawing wood-framing components of walls. The 'multipliers' may need a bit of work. Geared toward inches as measurement. Apologies to those who have moved-on from feet/inches. Best to 'set grid' before anything else. It helps you to see where you are at. entry example: 50.375 (inches) 4' 2 3/8 4'<space>2<space>3/8 the fraction portion relies on 2 spaces prior to it #ce #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantSex.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> ;#include <Excel.au3> Opt("GUIOnEventMode", 1) Opt("WinTitleMatchMode", 2) Global $relativeOrFixedChoice = 0;0 for relative, 1 for fixed Global $zeroX_Coordinate, $zeroY_Coordinate;direct-read, does not have multiplier Global $tempZero_X, $tempZero_y Global $ftInchMode, $inchMode Global $inputOfInterest, $numberInUse $guiWidth = @DesktopWidth - 900 $guiHeight = (@DesktopHeight * .955) - 105 $hGUI = GUICreate("", 897, 78, $guiWidth, $guiHeight, $WS_POPUP, $WS_EX_TOOLWINDOW) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "move_it") GUISetBkColor(0xABCDEF, $hGUI);(0x00ff00)while messing with gui. Else, (0xABCDEF) GUISetStyle($WS_POPUP, $WS_EX_LAYERED, $hGUI) _WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 255) WinSetOnTop($hGUI, "", 1);keeps you visible while touching the Excel sheet ;=======================================================offset copy controls $offsetX_Input = GUICtrlCreateInput("", 530, 8, 50, 21) $offsetY_Input = GUICtrlCreateInput("", 530, 32, 50, 21) $offsetX_Label = GUICtrlCreateLabel("X", 515, 8, 11, 17) GUICtrlSetColor(-1, 0xff00ff) $offsetY_Label = GUICtrlCreateLabel("Y", 515, 32, 11, 17) GUICtrlSetColor(-1, 0xff00ff) $offsetCopyButton = GUICtrlCreateButton("offset copy", 458, 8, 49, 41, $BS_MULTILINE) GUICtrlSetOnEvent($offsetCopyButton, "offsetCopy") ;=======================================================Insert drawing object controls $insertW_Input = GUICtrlCreateInput("20' 0", 368, 7, 50, 16) $insertH_Input = GUICtrlCreateInput("0' 5 1/2", 368, 25, 50, 16) $insertWidthLabel = GUICtrlCreateLabel("W", 352, 7, 15, 16) GUICtrlSetColor(-1, 0xff00ff) $insertHeightLabel = GUICtrlCreateLabel("H", 352, 25, 12, 16) GUICtrlSetColor(-1, 0xff00ff) $insertX_Input = GUICtrlCreateInput("0", 368, 43, 50, 16) $insertY_Input = GUICtrlCreateInput("0", 368, 61, 50, 16) $insertX_Label = GUICtrlCreateLabel("X", 352, 43, 15, 16) GUICtrlSetColor(-1, 0xff00ff) $insertY_Label = GUICtrlCreateLabel("Y", 352, 61, 15, 16) GUICtrlSetColor(-1, 0xff00ff) $insertButton = GUICtrlCreateButton("insert", 296, 8, 49, 41) GUICtrlSetOnEvent($insertButton, "insert") ;=======================================================Move. Relocate selection controls $setX_LocationInput = GUICtrlCreateInput("", 208, 8, 49, 21) $setY_LocationInput = GUICtrlCreateInput("", 208, 32, 49, 21) $setX_LocationLabel = GUICtrlCreateLabel("X", 192, 8, 11, 17) GUICtrlSetColor(-1, 0xff00ff) $setY_LocationLabel = GUICtrlCreateLabel("Y", 192, 32, 11, 17) GUICtrlSetColor(-1, 0xff00ff) $setLocationButton = GUICtrlCreateButton("move", 144, 8, 41, 41) GUICtrlSetOnEvent($setLocationButton, "setLocation") ;======================================================= Toggle co-ordinate system from 'relative to selected object' ;to 'from a fixed point' from set-zero section controls. $labelFixedCoOrd = GUICtrlCreateLabel("", 207, 54, 51, 19) GUICtrlSetState($labelFixedCoOrd, $GUI_DISABLE) GUICtrlSetBkColor($labelFixedCoOrd, 0xff0000) $setLocationFixedButton = GUICtrlCreateButton("fixed", 208, 55, 49, 17) GUICtrlSetOnEvent($setLocationFixedButton, "setRelativeOrFixedChoiceToFixed") $labelRelativeCoOrd = GUICtrlCreateLabel("", 143, 54, 51, 19) GUICtrlSetState($labelRelativeCoOrd, $GUI_DISABLE) GUICtrlSetBkColor($labelRelativeCoOrd, 0x00ff00) $setLocationRelativeButton = GUICtrlCreateButton("relative", 144, 55, 49, 17) GUICtrlSetOnEvent($setLocationRelativeButton, "setRelativeOrFixedChoiceToRelative") ;=======================================================Set grid $setGridButton = GUICtrlCreateButton("set grid", 78, 8, 41, 41, $BS_MULTILINE) GUICtrlSetOnEvent($setGridButton, "setGrid") ;=======================================================Resize object $setWidthInput = GUICtrlCreateInput("", 690, 8, 50, 21) $setHeightInput = GUICtrlCreateInput("", 690, 32, 50, 21) $setWidthLabel = GUICtrlCreateLabel("W", 665, 8, 15, 17) GUICtrlSetColor(-1, 0xff00ff) $setHeightLabel = GUICtrlCreateLabel("H", 665, 32, 11, 17) GUICtrlSetColor(-1, 0xff00ff) $setSizeButton = GUICtrlCreateButton("set size", 620, 8, 41, 41, $BS_MULTILINE) GUICtrlSetOnEvent($setSizeButton, "setSize") ;=======================================================Set the zero co-ordinate $setFixedZeroX_Input = GUICtrlCreateInput("48", 836, 8, 50, 21) GUICtrlSetTip($setFixedZeroX_Input, "inches only") $setFixedZeroY_Input = GUICtrlCreateInput("240", 836, 32, 50, 21) GUICtrlSetTip($setFixedZeroY_Input, "inches only") $setFixedZeroX_Label = GUICtrlCreateLabel("X", 815, 8, 11, 17) GUICtrlSetColor(-1, 0xff00ff) $setFixedZeroY_Label = GUICtrlCreateLabel("Y", 815, 32, 11, 17) GUICtrlSetColor(-1, 0xff00ff) $setFixedZeroButton = GUICtrlCreateButton("set zero", 778, 8, 33, 41, $BS_MULTILINE) GUICtrlSetOnEvent($setFixedZeroButton, "setZero") $xItButton = GUICtrlCreateButton("X", 26, 8, 33, 25);Not good physical placement within GUI. May need re-work. GUICtrlSetOnEvent($xItButton, "xIt") GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFF0000) ;=======================================================Find an open Excel book $oExcel = ObjGet("", "Excel.Application") $wintitle = WinGetTitle(".xls") ;=======================================================A solid grab-point for moving the GUI If $wintitle = "" Then $labelText = "Excel must be open first. Press here to refresh" Else $labelText = " X-LK-cad " & $wintitle EndIf $move_ItLabel = GUICtrlCreateLabel($labelText, 422, 56, 464, 17) GUICtrlSetOnEvent($move_ItLabel, "refreshOexcel") GUICtrlSetBkColor($move_ItLabel, 0x777777) GUICtrlSetColor($move_ItLabel, 0xffffff) ;=======================================================Enable/disable tooltips $tipEnableCheckbox = GUICtrlCreateCheckbox("", 28, 35, 15, 15) GUICtrlSetOnEvent($tipEnableCheckbox, "tipOnOff") GUICtrlSetState(-1, $GUI_UNCHECKED) GUICtrlSetTip(-1, "enable button tips") ;=======================================================Show auxillary controls $auxControlCheckbox = GUICtrlCreateCheckbox("", 50, 35, 15, 15) GUICtrlSetOnEvent($auxControlCheckbox, "gui2ShowHide") GUICtrlSetState(-1, $GUI_UNCHECKED) GUICtrlSetTip(-1, "aux. controls") ;=======================================================ft-inch or inch mode $checkBoxFtInch = GUICtrlCreateCheckbox("", 28, 54, 15, 15) GUICtrlSetTip($checkBoxFtInch, "feet & inch mode") GUICtrlSetOnEvent($checkBoxFtInch, "ftInchMode") $checkBoxInch = GUICtrlCreateCheckbox("", 50, 54, 15, 15) GUICtrlSetTip($checkBoxInch, "inches only mode") GUICtrlSetOnEvent($checkBoxInch, "inchMode") ;======================================================= GUISetState(@SW_SHOW, $hGUI) ftInchMode() ;=======================================================secondary GUI ;=======================================================gui with auxillary controls $hGUI2 = GUICreate("", 897, 78, $guiWidth, $guiHeight - 78, $WS_POPUP, $WS_EX_TOOLWINDOW, $hGUI) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "move_it2") GUISetBkColor(0xABCDEF);(0x00ff00)while messing with gui. Else, (0xABCDEF) GUISetStyle($WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED), $hGUI2) _WinAPI_SetLayeredWindowAttributes($hGUI2, 0xABCDEF, 255) ;=======================================================A solid grab-point for moving the GUI $move_ItLabel2 = GUICtrlCreateLabel("", 422, 56, 464, 17) GUICtrlSetBkColor($move_ItLabel2, 0x777777) ;=======================================================The ultimate script security. No theft possible; it is a gift. $sourceButton = GUICtrlCreateButton("", 890, 56, 7, 17) GUICtrlSetTip($sourceButton, "deposit source code at desktop") GUICtrlSetOnEvent($sourceButton, "source") ;=======================================================get size of selection $getSizeX_Input = GUICtrlCreateInput("", 836, 8, 50, 21) $getSizeY_Input = GUICtrlCreateInput("", 836, 32, 50, 21) $getSizeX_Label = GUICtrlCreateLabel("X", 815, 8, 11, 17) GUICtrlSetColor(-1, 0xff00ff) $getSizeY_Label = GUICtrlCreateLabel("Y", 815, 32, 11, 17) GUICtrlSetColor(-1, 0xff00ff) $getSizeButton = GUICtrlCreateButton("get size", 778, 8, 33, 41, $BS_MULTILINE) GUICtrlSetOnEvent($getSizeButton, "getSize") ;=======================================================Get location of selection $getX_LocationInput = GUICtrlCreateInput("", 690, 8, 50, 21) $getY_LocationInput = GUICtrlCreateInput("", 690, 32, 50, 21) $getX_LocationLabel = GUICtrlCreateLabel("X", 665, 8, 15, 17) GUICtrlSetColor(-1, 0xff00ff) $getY_LocationLabel = GUICtrlCreateLabel("Y", 665, 32, 11, 17) GUICtrlSetColor(-1, 0xff00ff) $getLocationButton = GUICtrlCreateButton("get location", 615, 8, 46, 41, $BS_MULTILINE) GUICtrlSetOnEvent($getLocationButton, "getLocation") ;=======================================================un-group all objects in sheet $unGroupAllButton = GUICtrlCreateButton("un-group all", 530, 8, 50, 41, $BS_MULTILINE) GUICtrlSetOnEvent($unGroupAllButton, "unGroupAll") GUISetState(@SW_HIDE, $hGUI2) ;=======================================================group all objects in sheet $groupAllButton = GUICtrlCreateButton("group all", 458, 8, 49, 41, $BS_MULTILINE) GUICtrlSetOnEvent($groupAllButton, "groupAll") ;=======================================================group selected objects $groupSelectionButton = GUICtrlCreateButton("group selection", 368, 7, 50, 41, $BS_MULTILINE) GUICtrlSetOnEvent($groupSelectionButton, "groupSelection") ;=======================================================rotate selection $rotateSelectionInput = GUICtrlCreateInput("", 270, 8, 49, 21) $rotateButton = GUICtrlCreateButton("rotate selection", 210, 8, 50, 41, $BS_MULTILINE) GUICtrlSetOnEvent($rotateButton, "rotateSelection") readZero();Set default zero X & Y coordinates While 1 Sleep(10) WEnd Func move_it();Grab the gray label to scoot the GUI around. _SendMessage($hGUI, $WM_SYSCOMMAND, 0xF012, 0) EndFunc ;==>move_it Func move_it2() _SendMessage($hGUI2, $WM_SYSCOMMAND, 0xF012, 0) EndFunc ;==>move_it2 Func xIt() Exit EndFunc ;==>xIt ;======================================================= ;Switch between feet-inches & inches only Func ftInchMode() GUICtrlSetState($checkBoxFtInch, $GUI_CHECKED) If GUICtrlRead($checkBoxFtInch) = $GUI_CHECKED Then $ftInchMode = 1 $inchMode = 0 GUICtrlSetState($checkBoxInch, $GUI_UNCHECKED) EndIf EndFunc ;==>ftInchMode Func inchMode() GUICtrlSetState($checkBoxInch, $GUI_CHECKED) If GUICtrlRead($checkBoxInch) = $GUI_CHECKED Then $ftInchMode = 0 $inchMode = 1 GUICtrlSetState($checkBoxFtInch, $GUI_UNCHECKED) EndIf EndFunc ;==>inchMode Func setGrid();=======================================================Sets grid to an emulation of 16" centers horizontal, 12" centers vertical.Gotta love Excels' 2-different-measurement system. Local $oErrorHandler = ObjEvent("AutoIt.Error", "errorFunc") If $wintitle <> "" Then; Prevent crash if no Excel book is open. With $oExcel .Rows.RowHeight = 19.50 .Columns.ColumnWidth = 4.14 EndWith EndIf EndFunc ;==>setGrid Func getFtInch($inputOfInterest) $numberInUse = "" $input = GUICtrlRead($inputOfInterest) ;If $inchMode = 1 And StringInStr($input, "'") = False Then ;>>>>>>>>>>>>>>>>>>>>>>>needs more thought, moving on without it ; MsgBox(0, "input error", "feet & inch mode") ;EndIf If StringInStr($input, "/") = False Then $FracSolved = 0 EndIf If StringInStr($input, "/") = True Then $frac = StringSplit($input, " ") $fracPortion = $frac[3] $fracSplit = StringSplit($fracPortion, "/") $fracnumerator = $fracSplit[1] $fracDenomenator = $fracSplit[2] $FracSolved = ($fracnumerator / $fracDenomenator) EndIf If StringInStr($input, "'") = True Then $inputSplit = StringSplit($input, "'") $feetSplit = $inputSplit[1] $inchSplit = $inputSplit[2] $inchFromFt = $feetSplit * 12 $numberInUse = $inchFromFt + $inchSplit + $FracSolved ;MsgBox(0, "", $numberInUse) EndIf If StringInStr($input, "'") = False Then Sleep(10) EndIf EndFunc ;==>getFtInch Func getInchOnly($inputOfInterest) $numberInUse = "" $input = GUICtrlRead($inputOfInterest) If StringInStr($input, "'") = False Then $numberInUse = $input ;MsgBox(0, "", $numberInUse) EndIf If StringInStr($input, "'") = True Then Sleep(10) EndIf EndFunc ;==>getInchOnly Func offsetCopy();=======================================================Copy & paste by a specified offset (inches). Multiple clicks/press enter gets multiple copies. If $wintitle <> "" Then Local $oErrorHandler = ObjEvent("AutoIt.Error", "errorFunc") Local $xMultiplier = 1.6048 Local $yMultiplier = 1.604995 If $inchMode = 1 Then Local $deltaX = Execute(GUICtrlRead($offsetX_Input)) * $xMultiplier Local $deltaY = Execute(GUICtrlRead($offsetY_Input)) * $yMultiplier * -1 EndIf If $ftInchMode = 1 Then getFtInch($offsetX_Input) $deltaX = $numberInUse * $xMultiplier getFtInch($offsetY_Input) $deltaY = $numberInUse * $yMultiplier * -1 EndIf With $oExcel Local $width = .Selection.ShapeRange.Width Local $height = .Selection.ShapeRange.Height $xLocation = .Selection.ShapeRange.Left $yLocation = .Selection.ShapeRange.Top $shapObject = .Selection.ShapeRange .Selection.Copy .ActiveSheet.Paste $x = $deltaX + $xLocation $y = $deltaY + $yLocation Sleep(10) .Selection.Left = $x .Selection.Top = $y .Selection.Width = $width .Selection.Height = $height EndWith EndIf EndFunc ;==>offsetCopy Func insert();=======================================================Insert drawing object. Rectangle, 1-point lineweight, black If $wintitle <> "" Then Local $oErrorHandler = ObjEvent("AutoIt.Error", "errorFunc") If $inchMode = 1 Then Local $width = Execute(GUICtrlRead($insertW_Input)) * 1.6048 Local $height = Execute(GUICtrlRead($insertH_Input)) * 1.604995 Local $xInsertPoint = Execute(GUICtrlRead($insertX_Input)) * 1.6048 Local $yInsertPoint = Execute(GUICtrlRead($insertY_Input)) * 1.604995 EndIf If $ftInchMode = 1 Then getFtInch($insertW_Input) $width = $numberInUse * 1.6048 getFtInch($insertH_Input) $height = $numberInUse * 1.604995 getFtInch($insertX_Input) $xInsertPoint = $numberInUse * 1.6048 getFtInch($insertY_Input) $yInsertPoint = $numberInUse * 1.604995 EndIf If $relativeOrFixedChoice = 0 Then $x = $xInsertPoint $y = $yInsertPoint - $height EndIf If $relativeOrFixedChoice = 1 Then $x = $xInsertPoint + ($zeroX_Coordinate * 1.6048) $y = (($yInsertPoint * -1) + ($zeroY_Coordinate * 1.604995)) - $height EndIf With $oExcel .ActiveSheet.Shapes.AddShape(1, $x, $y, $width, $height).Select; Shape type, X location, Y location, width, height $shapObject = .Selection.ShapeRange $shapObject.Fill.Visible = False $shapObject.Line.Weight = 1 $shapObject.Line.ForeColor.SchemeColor = 0;black ;$shapObject.Placement = .xlPlacement.xlFreeFloating (my) attempts to format as 'don't move or size with cells' has been fruitless EndWith EndIf EndFunc ;==>insert Func setLocation();=======================================================Essentially, 'move' selected. In excel, negatives move toward the left & top. A pain If $wintitle <> "" Then Local $oErrorHandler = ObjEvent("AutoIt.Error", "errorFunc") If $inchMode = 1 Then Local $deltaX = Execute(GUICtrlRead($setX_LocationInput)) * 1.6048;'Execute': Want to be able to enter '48.375+36.125' without doing head-math, focusing on the drawing instead. Local $deltaY = Execute(GUICtrlRead($setY_LocationInput)) * 1.604995 Local $fixedX = GUICtrlRead($setFixedZeroX_Input) * 1.6048 Local $fixedY = GUICtrlRead($setFixedZeroY_Input) * 1.604995 EndIf If $ftInchMode = 1 Then getFtInch($setX_LocationInput) $deltaX = $numberInUse * 1.6048 getFtInch($setY_LocationInput) $deltaY = $numberInUse * 1.604995 EndIf If $relativeOrFixedChoice = 0 Then;Move to a position relative to its' current position With $oExcel $xLocation = .Selection.ShapeRange.Left $yLocation = .Selection.ShapeRange.Top $shapObject = .Selection.ShapeRange $x = $deltaX + $xLocation $y = ($deltaY * -1) + $yLocation Sleep(10) .Selection.Left = $x .Selection.Top = $y EndWith Else; move to location from fixed-zero point With $oExcel $shapObject = .Selection.ShapeRange $height = .Selection.ShapeRange.Height; / 1.604995 $x = $deltaX + $fixedX $yFix = ($fixedY - $height) + ($deltaY * -1) Sleep(10) .Selection.Left = $x .Selection.Top = $yFix EndWith EndIf EndIf EndFunc ;==>setLocation Func setSize();=======================================================Resize selected drawing object If $wintitle <> "" Then Local $oErrorHandler = ObjEvent("AutoIt.Error", "errorFunc") Local $widthMultiplier = 1.6048 Local $htMultiplier = 1.604995 If $inchMode = 1 Then Local $width = Execute(GUICtrlRead($setWidthInput)) Local $height = Execute(GUICtrlRead($setHeightInput)) Local $translatedWidth = $width * $widthMultiplier Local $translatedHeight = $height * $htMultiplier EndIf If $ftInchMode = 1 Then getFtInch($setWidthInput) $width = $numberInUse $translatedWidth = $width * $widthMultiplier getFtInch($setHeightInput) $height = $numberInUse $translatedHeight = $height * $htMultiplier EndIf With $oExcel $shapObject = .Selection.ShapeRange $shapObject.Width = $translatedWidth $shapObject.Height = $translatedHeight EndWith EndIf EndFunc ;==>setSize Func setRelativeOrFixedChoiceToFixed();=================================(fixed) Set co-ordinate system to: relative to selected object; or from a fixed point from 'set zero' section. $relativeOrFixedChoice = 1 GUICtrlSetBkColor($labelFixedCoOrd, 0x00ff000);Change border-color surrounding the 2 buttons to help with visual I.D. GUICtrlSetBkColor($labelRelativeCoOrd, 0xff0000) EndFunc ;==>setRelativeOrFixedChoiceToFixed Func setRelativeOrFixedChoiceToRelative();=============================(relative) Set co-ordinate system to: relative to selected object; or from a fixed point from 'set zero' section. $relativeOrFixedChoice = 0 GUICtrlSetBkColor($labelFixedCoOrd, 0xff0000) GUICtrlSetBkColor($labelRelativeCoOrd, 0x00ff00) EndFunc ;==>setRelativeOrFixedChoiceToRelative Func readZero();====================================================Set global variable for zero co-ordinates #cs basic method of doing the feet & inchess thing Func ftOrInchSelect() $inputOfInterest = XXXXXXXXX If $ftInchMode = 1 Then getFtInch() EndIf If $inchMode = 1 Then getInchOnly() EndIf EndFunc #ce $zeroX = GUICtrlRead($setFixedZeroX_Input) $zeroY = GUICtrlRead($setFixedZeroY_Input) $zeroX_Coordinate = $zeroX $zeroY_Coordinate = $zeroY EndFunc ;==>readZero Func setZero();====================================================Get co-ordinates of selection #cs basic method of doing the feet & inchess thing Func ftOrInchSelect() $inputOfInterest = XXXXXXXXX If $ftInchMode = 1 Then getFtInch() EndIf If $inchMode = 1 Then getInchOnly() EndIf EndFunc #ce setRelativeOrFixedChoiceToRelative() Sleep(10) getLocation() Sleep(10) GUICtrlSetData($setFixedZeroX_Input, GUICtrlRead($getX_LocationInput)) GUICtrlSetData($setFixedZeroY_Input, GUICtrlRead($getY_LocationInput)) $zeroX_Coordinate = GUICtrlRead($getX_LocationInput) $zeroY_Coordinate = GUICtrlRead($getY_LocationInput) EndFunc ;==>setZero Func tipOnOff();====================================================Allows tips when needed & removes the annoyance when not needed. If GUICtrlRead($tipEnableCheckbox) = $GUI_CHECKED Then tipsOn() ElseIf GUICtrlRead($tipEnableCheckbox) = $GUI_UNCHECKED Then;My very first ElseIf! A simple Else seemed fine.... tipsOff() EndIf EndFunc ;==>tipOnOff Func tipsOn() GUICtrlSetTip($offsetCopyButton, "Copy selection & paste with X, Y offset." & @CRLF & " Multiple clicks (or press 'Enter') gets multiple pastes.") GUICtrlSetTip($insertButton, "Insert object. Set height, width & location first") GUICtrlSetTip($setLocationButton, "Move selection to X, Y distance from current (relative)" & @CRLF & "Or from 'set zero' point (fixed)") GUICtrlSetTip($setGridButton, 'Set grid to an emulation of 16" X, 12" Y.') GUICtrlSetTip($setSizeButton, "Resize selection") GUICtrlSetTip($setFixedZeroButton, "Set fixed zero co-ordinates using location of selection") GUICtrlSetTip($setLocationRelativeButton, "Co-ordinates for 'move' will come from selections' current location" & @CRLF & "'Insert' will be Y distance from top") GUICtrlSetTip($setLocationFixedButton, "Co-ordinates for 'move' will come from the 'set zero' option" & @CRLF & "'Insert' will be Y distance from 'set zero'") GUICtrlSetTip($xItButton, "Close") GUICtrlSetTip($getSizeButton, "get size of selection") GUICtrlSetTip($getLocationButton, "get location of selection" & @CRLF & "Y will be from top & X will be from leftwhen set to 'relative'" & @CRLF & "X & Y will be from 'set-zero' when set to 'fixed'") GUICtrlSetTip($unGroupAllButton, "un-group all objects on sheet") GUICtrlSetTip($groupSelectionButton, "group selected objects (hold ctrl & select objects)") GUICtrlSetTip($groupAllButton, "group all objects on sheet; selected or not") EndFunc ;==>tipsOn Func tipsOff() GUICtrlSetTip($offsetCopyButton, "") GUICtrlSetTip($insertButton, "") GUICtrlSetTip($setLocationButton, "") GUICtrlSetTip($setGridButton, "") GUICtrlSetTip($setSizeButton, "") GUICtrlSetTip($setFixedZeroButton, "") GUICtrlSetTip($setLocationRelativeButton, "") GUICtrlSetTip($setLocationFixedButton, "") GUICtrlSetTip($xItButton, "") GUICtrlSetTip($getSizeButton, "") GUICtrlSetTip($getLocationButton, "") GUICtrlSetTip($unGroupAllButton, "") GUICtrlSetTip($groupSelectionButton, "") GUICtrlSetTip($groupAllButton, "") EndFunc ;==>tipsOff Func refreshOexcel();==========================Allows reading Excel book that was started after script. I forget sometimes to stert Excel first. $oExcel = "" $wintitle = "" Sleep(100) $oExcel = ObjGet("", "Excel.Application") $wintitle = WinGetTitle(".xls") Sleep(100) If $wintitle <> "" Then $labelText = " X-LK-cad " & $wintitle GUICtrlSetData($move_ItLabel, $labelText) EndIf If $wintitle = "" Then $labelText = "Excel must be open first. Press here to refresh" GUICtrlSetData($move_ItLabel, $labelText) EndIf EndFunc ;==>refreshOexcel Func gui2ShowHide();==========================Hide / show auxillary controls If GUICtrlRead($auxControlCheckbox) = $GUI_CHECKED Then showAuxControls() ElseIf GUICtrlRead($auxControlCheckbox) = $GUI_UNCHECKED Then hideAuxControls() EndIf EndFunc ;==>gui2ShowHide Func showAuxControls() GUISetState(@SW_SHOW, $hGUI2) EndFunc ;==>showAuxControls Func hideAuxControls() GUISetState(@SW_HIDE, $hGUI2) EndFunc ;==>hideAuxControls ;======================================================================= ;=======================================================$hGUI2 functions Func getSize();==========================Returns the size of selection Local $oErrorHandler = ObjEvent("AutoIt.Error", "errorFunc") With $oExcel Local $width = .Selection.ShapeRange.Width / 1.6048 Local $x = Round($width, 3) Local $height = .Selection.ShapeRange.Height / 1.604995 Local $y = Round($height, 3) EndWith GUICtrlSetData($getSizeX_Input, $x) GUICtrlSetData($getSizeY_Input, $y) EndFunc ;==>getSize Func getLocation();==========================Returns the location of selection.'Relative': from left & top of sheet. 'fixed': from left & bottom of 'set-zero' point. If $relativeOrFixedChoice = 0 Then getLocationRelative() EndIf If $relativeOrFixedChoice = 1 Then getLocationFixed() EndIf EndFunc ;==>getLocation Func getLocationRelative() #cs not implemented yet Func ftOrInchSelect() $inputOfInterest = XXXXXXXXX If $ftInchMode = 1 Then getFtInch() EndIf If $inchMode = 1 Then getInchOnly() EndIf EndFunc #ce Local $oErrorHandler = ObjEvent("AutoIt.Error", "errorFunc") With $oExcel Local $height = .Selection.ShapeRange.Height / 1.604995 Local $xLocation = .Selection.ShapeRange.Left / 1.6048 Local $yLocation = .Selection.ShapeRange.Top / 1.604995 Local $x = Round($xLocation, 3) Local $y = Round($yLocation, 3) EndWith GUICtrlSetData($getX_LocationInput, $x) GUICtrlSetData($getY_LocationInput, $y + Round($height, 3)) EndFunc ;==>getLocationRelative Func getLocationFixed() #cs not implemented yet Func ftOrInchSelect() $inputOfInterest = XXXXXXXXX If $ftInchMode = 1 Then getFtInch() EndIf If $inchMode = 1 Then getInchOnly() EndIf EndFunc #ce Local $oErrorHandler = ObjEvent("AutoIt.Error", "errorFunc") Local $bottom = $zeroY_Coordinate With $oExcel Local $height = .Selection.ShapeRange.Height / 1.604995 Local $xLocation = .Selection.ShapeRange.Left / 1.6048 Local $yLocation = .Selection.ShapeRange.Top / 1.604995 Local $x = Round($xLocation, 3) - $zeroX_Coordinate Local $y = Round($yLocation, 3) EndWith GUICtrlSetData($getX_LocationInput, $x) $yRelative = $y + Round($height, 3) $yFixed = $bottom - $yRelative GUICtrlSetData($getY_LocationInput, $yFixed) EndFunc ;==>getLocationFixed Func unGroupAll();==========================Un-group all objects in sheet. Local $oErrorHandler = ObjEvent("AutoIt.Error", "errorFunc") With $oExcel .Application.ScreenUpdating = False .ActiveSheet.Shapes.SelectAll .Selection.Ungroup .Application.ScreenUpdating = True EndWith EndFunc ;==>unGroupAll Func groupAll();==========================Group all objects in sheet. Local $oErrorHandler = ObjEvent("AutoIt.Error", "errorFunc") With $oExcel .Application.ScreenUpdating = False .ActiveSheet.Shapes.SelectAll .Selection.Group .Application.ScreenUpdating = True EndWith EndFunc ;==>groupAll Func groupSelection();==========================Group selected objects. Local $oErrorHandler = ObjEvent("AutoIt.Error", "errorFunc") With $oExcel .Selection.Group EndWith EndFunc ;==>groupSelection Func rotateSelection();==========================Rotate selected objects. Positive entry is clockwise rotation. Local $oErrorHandler = ObjEvent("AutoIt.Error", "errorFunc") Local $rotationDegrees = GUICtrlRead($rotateSelectionInput) With $oExcel $shapObject = .Selection.ShapeRange $shapObject.rotation = $rotationDegrees EndWith EndFunc ;==>rotateSelection Func errorFunc() ;MsgBox(0, "", "no object selected");too confusing to need to press'O.K.' several times Sleep(100) EndFunc ;==>errorFunc ;Func newBook();haven't gone anywhere with this one ; Local $oExcel = _ExcelBookNew() ;setGrid() ;EndFunc ;==>newBook Func source();The ultimate in security for your script. ;Literal filepath. Change to where YOUR script is located. ;FileInstall("Q:\au3 projects\draw help IP\X-LK-cad.au3", @DesktopDir & "\X-LK-cad.au3") ;Check / fix source path. EndFunc ;==>source. Edited December 31, 2015 by lorenkinzel finally made setZero() work the way I wanted Link to comment Share on other sites More sharing options...
czyt Posted April 27, 2015 Share Posted April 27, 2015 (515,32) : error: _ExcelBookNew(): undefined function. I use version 3.3.12 AutoIt 董小姐,你微笑的时候很美,就像安河桥下,清澈的水... Link to comment Share on other sites More sharing options...
lorenkinzel Posted April 27, 2015 Author Share Posted April 27, 2015 I commented that func out as It is a 'future' thing & not used in the script as it stands. Link to comment Share on other sites More sharing options...
water Posted April 27, 2015 Share Posted April 27, 2015 czyt,AutoIt 3.3.12.0 comes with a completely rewritten version of the Excel UDF. The function names have changed, hence you get this error. Check the "script breaking changes" section in the AutoIt changelog for more details. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now