(defun GetCurrentSpace (Doc / BlkCol SpaceList CurSpace ActSpace temp1)
; Returns the "block object" for the active space
; Thanks to Jeff Mishler

(if (= (getvar "cvport") 1)
(vla-get-PaperSpace Doc)
(vla-get-ModelSpace Doc)
)
)

(defun SingleSelect (Listof Message Toggle / DiaLoad tmpStr tmpTog tmpList)

(setq DiaLoad (load_dialog "MD.dcl"))
(if (new_dialog "SingleSelect" DiaLOad)
(progn
(start_list "listbox" 3)
(mapcar 'add_list Listof)
(end_list)
(if Message
(set_tile "text1" Message)
)
(if (not Toggle)
(mode_tile "toggle1" 1)
)
(action_tile "listbox"
"(if (= $reason 4)
(progn
(setq tmpStr (get_tile \"listbox\"))
(if Toggle
(setq tmpTog (get_tile \"toggle1\"))
)
(done_dialog 1)
)
)"
)
(action_tile "accept"
"(progn
(setq tmpStr (get_tile \"listbox\"))
(if Toggle
(setq tmpTog (get_tile \"toggle1\"))
)
(done_dialog 1)
)"
)
(action_tile "cancel" "(done_dialog 0)")
(if (= (start_dialog) 1)
(progn
(setq tmpList (read (strcat "(" tmpStr ")")))
(if (= tmpTog "1")
(cons T tmpList)
tmpList
)
)
)
)
)
)

(defun MultiplyAxies (Xdir Ydir)
; Call like (MultiplyAxis (getvar "ucsxdir") (getvar "ucsydir"))
; to get the normal (z value) for the given ucs.

(list
(- (* (cadr Xdir) (caddr Ydir)) (* (caddr Xdir) (cadr Ydir)))
(- (* (caddr Xdir) (car Ydir)) (* (car Xdir) (caddr Ydir)))
(- (* (car Xdir) (cadr Ydir)) (* (cadr Xdir) (car Ydir)))
)
)
;------------------------------------------------------------------------
(defun GetObjectAxisVectors (Norm / Ax)
; Retruns a list of two vectors, firs is the X axis vector,
; the second is the Y axis vector.

(if
(and
(< (abs (car Norm)) (/ 1 64.0))
(< (abs (cadr Norm)) (/ 1 64.0))
)
(setq Ax (MultiplyAxies '(0.0 1.0 0.0) Norm)) ; first vector world Y Axis
(setq Ax (MultiplyAxies '(0.0 0.0 1.0) Norm)) ; first vector world Z Axis
)
(list Ax (MultiplyAxies Norm Ax))
)
;-----------------------------------------------------------------------------
(defun ArcCos (num)
; Posted by SMadsen @ theswamp.org
(cond ((4x4Matrix (ename / entData ptNorm Ang AxisList RotAng OppAng MainRotMatrix RotMatrix OppMatrix ptIns)

(setq entData (entget ename))
(setq MainRotMatrix
(list
(list 1.0 0.0 0.0 0.0)
(list 0.0 1.0 0.0 0.0)
(list 0.0 0.0 1.0 0.0)
(list 0.0 0.0 0.0 1.0)
)
)
(setq ptIns (append (cdr (assoc 10 entData)) '(1.0)))
(setq ptNorm (append (cdr (assoc 210 entData)) '(1.0)))
(setq AxisList (GetObjectAxisVectors ptNorm))
(setq Ang (cdr (assoc 50 entData)))
(if
(and
(not (equal (cadr AxisList) '(0.0 1.0 0.0) 0.0000001))
(setq RotAng (angle (cadr AxisList) '(0.0 1.0 0.0)))
(setq OppAng (- (* pi 2.0) RotAng))
)
(progn
(setq OppMatrix
(list
(list 1.0 0.0 0.0 0.0)
(list 0.0 (cos OppAng) (- (sin OppAng)) 0.0)
(list 0.0 (sin OppAng) (cos OppAng) 0.0)
(list 0.0 0.0 0.0 1.0)
)
)
(setq RotMatrix
(list
(list 1.0 0.0 0.0 0.0)
(list 0.0 (cos RotAng) (- (sin RotAng)) 0.0)
(list 0.0 (sin RotAng) (cos RotAng) 0.0)
(list 0.0 0.0 0.0 1.0)
)
)
(setq MainRotMatrix
(mxm
MainRotMatrix
RotMatrix
)
)
(setq ptNorm (mxv OppMatrix ptNorm))
(setq ptIns (mxv RotMatrix ptIns))
)
)
(if
(and
(not (equal (car AxisList) '(1.0 0.0 0.0) 0.0000001))
(setq RotAng (angle (car AxisList) '(1.0 0.0 0.0)))
(setq OppAng (- (* pi 2.0) RotAng))
)
(progn
(setq OppMatrix
(list
(list (cos OppAng) 0.0 (sin OppAng) 0.0)
(list 0.0 1.0 0.0 0.0)
(list (- (sin OppAng)) 0.0 (cos OppAng) 0.0)
(list 0.0 0.0 0.0 1.0)
)
)
(setq RotMatrix
(list
(list (cos RotAng) 0.0 (sin RotAng) 0.0)
(list 0.0 1.0 0.0 0.0)
(list (- (sin RotAng)) 0.0 (cos RotAng) 0.0)
(list 0.0 0.0 0.0 1.0)
)
)
(setq MainRotMatrix
(mxm
MainRotMatrix
RotMatrix
)
)
(setq ptNorm (mxv OppMatrix ptNorm))
(setq ptIns (mxv RotMatrix ptIns))
)
)
(if
(and
(equal ptNorm '(0.0 0.0 1.0 1.0) 0.0000001)
(not (equal Ang 0.0))
)
(setq MainRotMatrix
(mxm
MainRotMatrix
(list
(list (cos Ang) (- (sin Ang)) 0.0 0.0)
(list (sin Ang) (cos Ang) 0.0 0.0)
(list 0.0 0.0 1.0 0.0)
(list 0.0 0.0 0.0 1.0)
)
)
)
)
;(print ptIns)
;(print Matrix)
(mxm
(list
(list (cdr (assoc 41 entData)) 0.0 0.0 (car ptIns))
(list 0.0 (cdr (assoc 42 entData)) 0.0 (cadr ptIns))
(list 0.0 0.0 (cdr (assoc 43 entData)) (caddr ptIns))
(list 0.0 0.0 0.0 1.0)
)
MainRotMatrix
)
)
|;
;-----------------------------------------------------------
; By gile @ theswamp, works great.
(defun ename->4x4Matrix (ename / entData ang norm mat)
(setq entData (entget ename))
(setq ang (- (cdr (assoc 50 entData))))
(setq norm (cdr (assoc 210 entData)))

;; a 3X3 matrix as this returned by (butlast (caddr (nentsel)))
(setq mat (mxm
;; scale
(list (list (cdr (assoc 41 entData)) 0.0 0.0)
(list 0.0 (cdr (assoc 42 entData)) 0.0)
(list 0.0 0.0 (cdr (assoc 43 entData)))
)
(mxm
;; rotation on Z axis ...
(list (list (cos ang) (- (sin ang)) 0.0)
(list (sin ang) (cos ang) 0.0)
'(0.0 0.0 1.0)
)
;; ... of OCS
(mapcar '(lambda (v) (trans v norm 0 T))
'((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0))
)
)
)
)

;; the 4X4 matrix as this returned by (caddr (nentselp))
(append
(mapcar
'(lambda (v1 v2)
(append v1 (list v2))
)
(apply 'mapcar (cons 'list mat)) ; transposed 3X3 matrix
(trans (cdr (assoc 10 entData)) norm 0) ; deplacement
)
(list '(0.0 0.0 0.0 1.0))
)
)
;---------------------------------------------------------------------------------------
;; Apply a transformation matrix to a vector,
;; by Vladimir Nesterovsky
(defun mxv (m v)
(mapcar '(lambda (row) (apply '+ (mapcar '* row v))) m)
)
;; Multiply two matrices, by Vladimir Nesterovsky.
(defun mxm (m q / qt)
(setq qt (apply 'mapcar (cons 'list q)))
(mapcar '(lambda (mrow) (mxv qt mrow)) m)
)

;========================================================================================

(defun c:con (/ *error* ActDoc BlkCol dbxApp oVer Sel EntList tempStr tempList cnt DiaRtn Pos ObjCopy
NewObj Matrix tempEntData tempEntType tempBlkName tempPos testMatrix)
; Copy objects in place, nested or not.
; Sub's '*error* 'GetCurrentSpace 'ename->4x4Matrix 'SingleSelect

(defun *error* (msg)

(vla-EndUndoMark ActDoc)
(if dbxApp (vl-catch-all-apply 'vlax-release-object (list dbxApp)))
(setq dbxApp nil)
(prompt (strcat "\n Error-->: " msg))
)
;-------------------------------------------------------------
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-EndUndoMark ActDoc)
(vla-StartUndoMark ActDoc)
(setq BlkCol (vla-get-Blocks ActDoc))
(setq dbxApp
(if ( (length Sel) 2)
(progn
(setq EntList (cons (car Sel) (last Sel)))
(setq tempStr "")
(setq tempList nil)
(foreach ename EntList
(if (not (equal ename (last EntList)))
(progn
(setq tempEntData (entget ename))
(setq tempEntType (cdr (assoc 0 tempEntData)))
(setq tempList
(cons
(strcat
tempStr
tempEntType
(if (= tempEntType "INSERT")
(progn
(setq tempBlkName (cdr (assoc 2 tempEntData)))
(if (setq tempPos (vl-string-search "|" tempBlkName))
(setq tempBlkName (substr tempBlkname (+ tempPos 2)))
)
(strcat " [ " tempBlkName " ]")
)
""
)
)
tempList
)
)
(if (= tempStr "")
(setq tempStr " |-> ")
(setq tempStr (strcat " " tempStr))
)
)
)
)
(if
(or
(and
(<= (length EntList) 2)
(setq DiaRtn 0)
(setq cnt 1)
)
(and
(setq DiaRtn (SingleSelect (reverse tempList) "Select item to copy." nil))
(setq DiaRtn (car DiaRtn))
(setq cnt (1+ DiaRtn))
(= ncnt cnt)
(setq nlst (cons i nlst))
)
(setq ncnt (1+ ncnt))
)
nlst
)
EntList
cnt
)
)
(if (setq Pos (vl-position :vlax-true (mapcar '(lambda (x) (vla-get-IsXref (vla-Item BlkCol (cdr (assoc 2 (entget x)))))) tempList)))
(progn
(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Open (list dbxApp (findfile (vla-get-Path (vlax-ename->vla-object (nth Pos tempList)))))))
(exit)
)
(setq ObjCopy
(vlax-invoke
dbxApp
'HandleToObject
(vla-get-Handle
(vlax-ename->vla-object
(nth DiaRtn EntList)
)
)
)
)
)
(progn
(setq dbxApp ActDoc)
(setq ObjCopy (vlax-ename->vla-object (nth DiaRtn EntList)))
)
)
(setq NewObj (car (vlax-invoke dbxApp 'CopyObjects (list ObjCopy) (GetCurrentSpace ActDoc))))
(while (4x4Matrix (nth cnt EntList)))
;(print Matrix)
;|
(setq testMatrix
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray vlax-vbDouble '(0 . 3) '(0 . 3))
Matrix
)
)
)
(vla-TransformBy NewObj testMatrix)
example by Gile @ theswamp works.
|;
(vla-TransformBy NewObj (vlax-tmatrix Matrix))
(setq cnt (1+ cnt))
)
(vla-Highlight NewObj :vlax-true)
)
)
(prompt "\n Copy successful.")
)
(prompt "\n No object copied!")
)
)
(vla-Regen ActDoc acActiveViewport)
(vla-EndUndoMark ActDoc)
(if dbxApp (vl-catch-all-apply 'vlax-release-object (list dbxApp)))
(setq dbxApp nil)
(princ)
)
;======================================================

(defun c:CopyNestedLayer (/ ActDoc Sel EntList DiaRtn tempList LayName tempEnt tempData CopyList NewObjList Matrix Newss
dbxApp oVer cnt tempPos *error*)

(defun *error* (msg)

(vla-EndUndoMark ActDoc)
(if dbxApp (vlax-release-object dbxApp))
(setq dbxApp nil)
(if msg
(progn
(prompt (strcat "\n Error-> " msg))
(vl-bt)
)
)
)
;-------------------------------------------
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-EndUndoMark ActDoc)
(vla-StartUndoMark ActDoc)
(setvar 'ErrNo 0)
(while (not (equal (getvar 'ErrNo) 52))
(if
(and
(setq Sel (nentsel "\n Select object of nested layer to copy: "))
(> (length Sel) 2)
(setq EntList (append (list (car Sel)) (last Sel)))
(setq EntList
(if (> (length EntList) 2)
(if
(setq DiaRtn
(SingleSelect
(mapcar
'(lambda (x / tempData)
(setq tempData (entget x))
(strcat
(cdr (assoc 8 tempData))
" [ "
(cdr (assoc 0 tempData))
" ]"
)
)
EntList
)
"Select layer to copy."
nil
)
)
(progn
(setq tempList nil)
(setq DiaRtn (car DiaRtn))
(setq cnt DiaRtn)
(while (< cnt (length EntList))
(setq tempList (cons (nth cnt EntList) tempList))
(setq cnt (1+ cnt))
)
(setq EntList (reverse tempList))
)
)
EntList
)
)
(setq LayName (cdr (assoc 8 (entget (car EntList)))))
(setq tempEnt (tblobjname "block" (cdr (assoc 2 (entget (last EntList))))))
(if (equal (logand (cdr (assoc 70 (setq tempData (entget tempEnt)))) 4) 4)
(progn
(setq dbxApp
(if (vla-object tempEnt) CopyList))
)
)
CopyList
)
)
)
(progn
(setq NewObjList (vlax-invoke dbxApp 'CopyObjects CopyList (GetCurrentSpace ActDoc)))
(setq Matrix (ename->4x4Matrix (last EntList)))
(foreach tempObj NewObjList
(vla-TransformBy tempObj (vlax-tmatrix Matrix))
)
(setq Newss nil)
(setq Newss (ssadd))
(foreach tempObj NewObjList
(ssadd (vlax-vla-object->ename tempObj) Newss)
)
(sssetfirst nil Newss)
(setq CopyList nil)
(prompt (strcat "\n Copied layer: " LayName ", Object count: " (itoa (length NewObjList))))
)
)
)
(vla-EndUndoMark ActDoc)
(*error* nil)
(princ)
)

(c:con)

****** MD.dcl ********

UnBlank : dialog { label = "UnBlank" ; width = 40 ; height = 27 ;
: row
{
: list_box { label = "Select items to unblank." ; key = "listbox1" ; width = 25 ; multiple_select = false ;}
: column {
: spacer {}
: column {
:spacer {}
: button { label = "UnBlank" ; key = "UnBlank1" ; width = 1 ; fixed_width = true ; }
: toggle { label = "Zoom when UnBlanking?" ; key = "Tog1" ; value = 1 ; }
: button { label = "Zoom extents" ; key = "Zoom1" ; width = 1 ; fixed_width = true ; }
: spacer {}
}
: button { label = "Draw Boundry Box" ; key = "BB1" ; width = 1 ; fixed_width = true ; }
: button { label = "Re-Blank" ; key = "ReBlank1" ; width = 1 ; fixed_width = true ; }
: button { label = "UnBlank All" ; key = "UnBlank2" ; width = 1 ; fixed_width = true ; }
: button { label = "Done" ; key = "Cancel" ; is_cancel = true ; width = 1 ; fixed_width = true ; }
: spacer {}
}
}
}
//-----------------------------------------------------------------------------------------

SingleSelect : dialog{ label = "Select Item";
: list_box { key = "listbox"; width = 55; height = 25; tabs = 10;}
: toggle { key = "toggle1"; }
: text { key = "text1"; }
: row {
: spacer { width = 1; }
: button { label = "OK"; is_default = true; allow_accept = true; key = "accept"; width = 8; fixed_width = true; }
: button { label = "Cancel"; is_cancel = true; key = "cancel"; width = 8; fixed_width = true; }
: spacer { width = 1;}
}
}
//-------------------------------------------------------------------------------------------

MultiSelect : dialog{ label = "Select Item";
: list_box { key = "listbox"; width = 55; height = 25; multiple_select = true; }
: toggle { key = "toggle1"; }
: text { key = "text1"; }
: row {
: spacer { width = 1; }
: button { label = "OK"; is_default = true; allow_accept = true; key = "accept"; width = 8; fixed_width = true; }
: button { label = "Cancel"; is_cancel = true; key = "cancel"; width = 8; fixed_width = true; }
: spacer { width = 1;}
}
}
//-------------------------------------------------------------------------------------------

XrefRe : dialog {label = "Xref RePath and ReName."; width = 100; height = 22;

: row {
: list_box { label = "Drawings (Xref's)"; key = "DwgList"; width = 25; height = 17;}
: column { height = 10;
: spacer {}
: boxed_column {
: text { key = "text1"; }
: edit_box { label = "New name for Xref."; key = "NewName"; width = 20; }
: boxed_column { label = "Path type.";
: radio_row { key = "PathType"; width = 20;
: radio_button { label = "Relative"; key = "PathRel"; }
: radio_button { label = "Full"; key = "PathFull"; }
: radio_button { label = "None"; key = "PathNone"; value = 1; }
}
: edit_box { label = "Relative path:"; key = "Path"; width = 20; }
}
: row {
: spacer {}
: button { label = "v Proceed v"; key = "Proceed"; width = 10;}
: spacer {}
}
}
: boxed_column {
: list_box { label = "Xref names: Old to New"; key = "XrefList"; width = 22; height = 7; tabs = "10";}
: row {
: spacer {}
: button { label = "Remove selection"; key = "Remove"; fixed_width = true; }
: spacer {}
}
}
}
}
: row {
: spacer {}
: button { label = "Process current directory"; key = "Accept"; is_default = true; allow_accept = true; width = 8; fixed_width = true; }
: button { label = "Select new directory"; key = "NewDir"; width = 8; fixed_width = true; }
: button { label = "Cancel"; key = "Cancel"; is_cancel = true; width = 8; fixed_width = true; }
: spacer {}
}
}

//---------------------------------------------------------------------------------------

MyPropsTest : dialog { label = "Properties to edit.";
: text { label = "Thanks Michael Puckett!! @ http://www.theswamp.org"; }
: column {
: list_box { label = "List of properties to modify"; key = "PropsListbox"; height = 25; width = 80; tabs = 40;}
: text { key = "TextLabel"; }
: edit_box { key = "PropsEditbox"; }
: row {
: spacer {}
: button { label = "Pick point"; key = "PickPt"; }
: button { label = "Pick from list"; key = "PickList"; }
: button { label = "Help"; key = "HelpProp"; }
: spacer {}
}
: row {
: spacer {}
: button { label = "Apply"; key = "accept"; allow_accept = true; is_default = true; }
: button { label = "Done"; key = "cancel"; is_cancel = true; }
: spacer {}
}
: text { key = "TextResults"; }
}
}

//-------------------------------------------------------------------------------------------

MyPropsList : dialog { label = "Select item from list.";
: list_box { key = "PropsListbox2"; height = 20; width = 40; }
: button { label = "Cancel"; key = "cancel"; is_cancel = true; }
}

//--------------------------------------------------------------------------------------------

AttListDialog : dialog { label = "Attribute tags for blocks selected.";
: column {
: list_box { label = "Attribute tags Number of attribute(s)."; key = "AttListbox"; width = 60; height = 20; tabs = 30; }
: row {
: text { key = "AttTextLabel"; }
: edit_box { key = "AttEditbox"; }
: button { label = "Pick Ext."; key = "PickExisting"; width = 10; fixed_width = true; }
}
: row {
: button { label = "List Prompts"; key = "PromptList"; }
: button { label = "Apply"; key = "Accept"; }
: button { label = "Done"; key = "Cancel"; is_cancel = true; }
}
}
}

//-------------------------------------------------------------------------------------------

MergeTextStyles : dialog { label = "Merge text styles [ v3.0 ]";
: row {
: list_box { label = "Styles found in use."; key = "ToMerge"; width = 60; height = 15; tabs = 23; multiple_select = true; }
: column {
: spacer {}
: button { label = "List objects"; key = "ObjListBtn"; width = 10; }
: spacer {}
: button { label = "Merge"; key = "MergeBtn"; width = 10; }
: spacer {}
: button { label = "Remove"; key = "RemoveBtn"; width = 10; }
}
: list_box { label = "Styles to merge to."; key = "MergeTo"; width = 40; height = 15; tabs = 23; }
}
: list_box { label = "Merge list"; key = "ShowMerge"; width = 60; height = 10; tabs = 40; multiple_select = true; }
: row { label = "Creat new style";
: edit_box { label = "Style name:"; key = "StyleName"; }
: popup_list { label = "Select font"; key = "FontListbox"; width = 50; }
: button { label = "Create"; key = "CreateBtn"; width = 15; fixed_width = true; }
}
: spacer {}
: row { label = "Current system variables";
: column {
: row {
: text { key = "Text01"; }
: popup_list { label = "Select new text style"; key = "DimTxStyList"; }
}
: row {
: text { key = "Text02"; }
: popup_list { label = "Select new text style"; key = "TextStyleList"; }
}
}
}
: row {
: toggle { label = " Delete style(s) after merge?"; key = "DeleteTgl"; value = "1"; }
: button { label = "Proceed"; key = "ProBtn"; is_accept = true; }
: button { label = "Cancel"; key = "CanBtn"; is_cancel = true; }
}
}

//---------------------------------------------------------------------------------------------

ImportText : dialog { label = "Import text file [ v1.0 ]";
: row {
: column {
: boxed_column { label = "Delimiated type";
: radio_button { label = "Tab"; key = "TabRad"; }
: radio_button { label = "Comma"; key = "CommaRad"; }
: row {
: radio_button { label = "Other"; key = "OtherRad"; }
: edit_box { width = 5; key = "OtherEb"; }
}
}
: radio_row { label = "Make all letters capital?";
:radio_button { label = "Yes"; key = "CapYesRad"; }
:radio_button { label = "No"; key = "CapNoRad"; }
}
}
: boxed_column { label = "Text options";
: edit_box { label = "Text height"; width = 20; fix_width = true; key = "TextHtEb"; }
: edit_box { label = "Height space ratio"; width = 20; key = "HtRatEb"; }
: edit_box { label = "Line spacing ratio"; width = 20; key = "LnSpcRatEb"; }
}
: boxed_column { label = "Table type"; key = "TblTypeCol";
: row {
: radio_button { label = "Plain text"; key = "TextRad"; }
: radio_button { label = "Table"; key = "TblRad"; }
}
: row {
: column {
: boxed_radio_row { label = "Draw grid lines?"; key = "GridRadCol";
: radio_button { label = "Yes"; key = "GridYesRad"; }
: radio_button { label = "No"; key = "GridNoRad"; }
}
: spacer {}
: popup_list { label = "Alignment"; width = 30; key = "AliPul"; }
}
: column {
: boxed_radio_column { label = "Title row"; key = "TitleRadCol";
: radio_button { label = "Yes"; key = "TitleYesRad"; }
: radio_button { label = "No"; key = "TitleNoRad"; }
}
: boxed_radio_column { label = "Header row"; key = "HeadRadCol";
: radio_button { label = "Yes"; key = "HeadYesRad"; }
: radio_button { label = "No"; key = "HeadNoRad"; }
}
}
}
}
}
: edit_box { label = "Replace empty strings with"; key = "RplcStrEb"; }
: row {
: popup_list { label = "Text style to use"; width = 50; fixed_width = true; key = "TextStyPul"; }
: button { label = "Proceed"; is_accept = true; width = 10; fixed_width = 10; key = "ProBtn"; }
: button { label = "Cancel"; is_cancel = true; width = 10; fixed_width = 10; key = "CanBtn"; }
}
}

Advertisements