LEADER
下列組碼適用於引線圖元。
引線組碼
組碼說明
100子類標記 (AcDbLeader)
3標注樣式名稱
71箭頭標誌:0 = 禁用;1 = 可用
72引線路徑類型:0 = 直線段;1 = 樣條曲線
73引線創建標誌(缺省值= 3):
0 = 與文本註釋一起創建引線;
1 = 與公差註釋一起創建引線;
2 = 與塊引用註釋一起創建引線;
3 = 創建引線,沒有任何註釋;
74鉤線方向標誌:
0 = 鉤線(或樣條引線的切線結束)方向與水平矢量方向相反;
1 = 鉤線(或樣條引線的切線結束)方向與水平矢量方向相同(請參見組碼 75);
75鉤線標誌:0 = 無鉤線;1 = 有鉤線
40文字註釋高度
41文字註釋寬度
76引線中的頂點數(DXFIN 時被忽略)
10頂點坐標(適用於每個頂點的條目)DXF:X 值;APP:三維點
20, 30DXF:頂點坐標的 Y 和 Z 值
77當引線的 DIMCLRD=BYBLOCK 時使用的顏色
340關聯註釋的固定引用(多行文字,公差或插入圖元)
210法線矢量。DXF:X 值;APP:三維矢量
220, 230DXF:法線矢量的 Y 和 Z 值
211引線的「水平」方向。DXF:X 值;APP:三維矢量。
221,231DXF:引線的「水平」方向的 Y 和 Z 值
212塊引用插入點距最終引線頂點的偏移。:X 值;APP:三維矢量
222,232DXF:塊引用插入點距最終引線頂點的偏移的 Y 和 Z 值。
213註釋位置點距最終引線頂點的偏移。DXF:X 值;APP:三維矢量
223,233DXF:註釋位置點距最終引線頂點的偏移的 Y 和 Z 值。
下列組碼適用於引線圖元。
引線組碼
組碼說明
100子類標記 (AcDbLeader)
3標注樣式名稱
71箭頭標誌:0 = 禁用;1 = 可用
72引線路徑類型:0 = 直線段;1 = 樣條曲線
73引線創建標誌(缺省值= 3):
0 = 與文本註釋一起創建引線;
1 = 與公差註釋一起創建引線;
2 = 與塊引用註釋一起創建引線;
3 = 創建引線,沒有任何註釋;
74鉤線方向標誌:
0 = 鉤線(或樣條引線的切線結束)方向與水平矢量方向相反;
1 = 鉤線(或樣條引線的切線結束)方向與水平矢量方向相同(請參見組碼 75);
75鉤線標誌:0 = 無鉤線;1 = 有鉤線
40文字註釋高度
41文字註釋寬度
76引線中的頂點數(DXFIN 時被忽略)
10頂點坐標(適用於每個頂點的條目)DXF:X 值;APP:三維點
20, 30DXF:頂點坐標的 Y 和 Z 值
77當引線的 DIMCLRD=BYBLOCK 時使用的顏色
340關聯註釋的固定引用(多行文字,公差或插入圖元)
210法線矢量。DXF:X 值;APP:三維矢量
220, 230DXF:法線矢量的 Y 和 Z 值
211引線的「水平」方向。DXF:X 值;APP:三維矢量。
221,231DXF:引線的「水平」方向的 Y 和 Z 值
212塊引用插入點距最終引線頂點的偏移。:X 值;APP:三維矢量
222,232DXF:塊引用插入點距最終引線頂點的偏移的 Y 和 Z 值。
213註釋位置點距最終引線頂點的偏移。DXF:X 值;APP:三維矢量
223,233DXF:註釋位置點距最終引線頂點的偏移的 Y 和 Z 值。
;;#################################################################70
LEADER + reactor
http://www.cadtutor.net/forum/showthread.php?t=13528&page=2
(vl-load-com)
LEADER + reactor
http://www.cadtutor.net/forum/showthread.php?t=13528&page=2
(vl-load-com)
(defun c:lron(/ oldName)
(if(not lr:Name)(setq lr:Name "text"))
(setq oldName lr:Name)
(setq lr:Name
(getstring T
(strcat "\nSpecify layer to move qleaders <"
lr:Name ">: ")))
(if(= "" lr:Name)(setq lr:Name oldName))
(if(not(tblsearch "LAYER" lr:Name))
(vla-Add
(vla-get-Layers
(vla-get-ActiveDocument
(vlax-get-acad-object)))lr:Name)
); end if
(if
(not qleader:Reactor)
(progn
(setq qleader:Reactor
(vlr-command-reactor lr:Name
'((:vlr-commandended . PutLeaderToText))))
(princ "\n<<< QLeader reactor now ON >>>")
); end progn
(princ "\nQLeader already ON! ")
); end if
(princ)
); end of LeaderToTextLayer
(if(not lr:Name)(setq lr:Name "text"))
(setq oldName lr:Name)
(setq lr:Name
(getstring T
(strcat "\nSpecify layer to move qleaders <"
lr:Name ">: ")))
(if(= "" lr:Name)(setq lr:Name oldName))
(if(not(tblsearch "LAYER" lr:Name))
(vla-Add
(vla-get-Layers
(vla-get-ActiveDocument
(vlax-get-acad-object)))lr:Name)
); end if
(if
(not qleader:Reactor)
(progn
(setq qleader:Reactor
(vlr-command-reactor lr:Name
'((:vlr-commandended . PutLeaderToText))))
(princ "\n<<< QLeader reactor now ON >>>")
); end progn
(princ "\nQLeader already ON! ")
); end if
(princ)
); end of LeaderToTextLayer
(defun c:lroff()
(if qleader:Reactor
(progn
(vlr-Remove qleader:Reactor)
(setq qleader:Reactor nil)
(princ "\n<<< QLeader reactor now OFF >>>")
); end progn
); end if
(princ)
); end of c:lroff
(if qleader:Reactor
(progn
(vlr-Remove qleader:Reactor)
(setq qleader:Reactor nil)
(princ "\n<<< QLeader reactor now OFF >>>")
); end progn
); end if
(princ)
); end of c:lroff
(defun PutLeaderToText(reac args / curText curLead layName)
(setq layName(vlr-Data reac))
(if(eq "QLEADER"(car args))
(progn
(setq curText(vlax-ename->vla-object(entlast))
curLead(vlax-ename->vla-object
(cdr(assoc 330(entget(entlast)))))
); end setq
(if
(or
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-Layer
(list curText layName)))
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-Layer
(list curLead layName)))
); end or
(princ "*** WARNING! Can't move leader from locked layer. ***")
); end if
); end progn
); end if
(princ)
); end of PutLeaderToText
(setq layName(vlr-Data reac))
(if(eq "QLEADER"(car args))
(progn
(setq curText(vlax-ename->vla-object(entlast))
curLead(vlax-ename->vla-object
(cdr(assoc 330(entget(entlast)))))
); end setq
(if
(or
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-Layer
(list curText layName)))
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-Layer
(list curLead layName)))
); end or
(princ "*** WARNING! Can't move leader from locked layer. ***")
); end if
); end progn
); end if
(princ)
); end of PutLeaderToText
(princ "\nLRON - switch on qleader reactor, LROFF - switch off qleader reactor
;;;******************************************************************
http://www.cadopolis.com/shareware/downloadshareware.asp?
http://www.cadopolis.com/shareware/downloadshareware.asp?
TheDateTimeFile=1902200320423PMForEachDrawing4Demo.zip&TheDateTimeFile2=ForEachDrawing4
;;;******************************************************************
http://www.mjtd.com/bbs/Archive_view.asp?boardID=3&ID=18953
引線標注
;;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun c:bia(/ n pt txt pt1 pt2 pt3 pttxt d)
(setq n(getint "\\n 輸入標示零件個數: " )
txt(getstring "\\n 輸入起始零件序號: " )
d(getstring "\\n 在左還是在右<在左>: ")
pt(getpoint "\\n 輸入標記線連接點: " )
)
(if(= "r" d)
(setq pt(list (- (car pt) (+ (* 6 n) (* 2 (- n 1)))) (cadr pt)))
)
http://www.mjtd.com/bbs/Archive_view.asp?boardID=3&ID=18953
引線標注
;;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun c:bia(/ n pt txt pt1 pt2 pt3 pttxt d)
(setq n(getint "\\n 輸入標示零件個數: " )
txt(getstring "\\n 輸入起始零件序號: " )
d(getstring "\\n 在左還是在右<在左>: ")
pt(getpoint "\\n 輸入標記線連接點: " )
)
(if(= "r" d)
(setq pt(list (- (car pt) (+ (* 6 n) (* 2 (- n 1)))) (cadr pt)))
)
(setq pt1(list (+ (car pt) 6) (cadr pt))
pttxt(list (+ (car pt) 3) (+ (cadr pt) 2.4))
)
pttxt(list (+ (car pt) 3) (+ (cadr pt) 2.4))
)
(setq cl(getvar "clayer"))
(setq os(getvar "osmode"))
(setvar "clayer" "w文字標注")
(setvar "osmode" 0)
(command"line" pt pt1 "")
(command"text" "mc" pttxt 3.5 0 txt)
(repeat (- n 1)
(setq pt2(polar pt1 (/ (* pi 7) 4) 1.41421))
(command"line" pt1 pt2 "")
(setq pt3(polar pt2 (/ pi 4) 1.41421))
(setq pt4(list (+ (car pt3) 6) (cadr pt3)))
(command"line" pt2 pt3 pt4 "")
(setq pttxt(list (+ (car pt3) 3) (+ (cadr pt) 2.4)))
(setq txt (rtos (+ (atoi txt) 1) 2 0))
(print txt)
(command "text" "MC" pttxt 3.5 0 txt)
(setq pt1 pt4)
)
(setvar "clayer" cl)
(setvar "osmode" os)
)
;;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;; 版權所有 (C) 1991-2000 明經通道 鄭立楷
;;
;; 本軟件免費可供進行任何用途需求的拷貝、修改及發行, 但請遵循下述原則:
;;
;; 1) 上列的版權通告必須出現在每一份拷貝裡。
;; 2) 相關的說明文檔也必須載有版權通告及本項許可通告。
;;
;; 本軟件僅提供作為應用上的參考, 而未聲明或隱含任何保證; 對於任何特殊
;; 用途之適應性, 以及商業銷售所隱含作出的保證, 在此一概予以否認。
;;
;; http://www.mjtd.com http://www.mccad.net
;;
;; e-mail:mccad@mjtd.com
;;
;;
(princ"\n總裝明細序號填寫程序")
(defun c:mxxh(/ oldecho oldlayer oldstyle oldsize oldpwid oldsnap oldortho
sele txto txt pt_s pt_m pt_t pt_r pt_l pt_c pt_e tt num)
(setq oldecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq oldlayer (getvar "clayer"))
(if (=(tblobjname "LAYER" "3") nil)
(progn
(entmake (list
'(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
'(6 . "CONTINUOUS")
'(62 . 3)
'(70 . 0)
(cons 2 "3")
)
)
)
)
(setvar "clayer" "3")
(setq oldstyle (getvar "textstyle"))
(setq oldsize (getvar "textsize"))
(setq oldpwid (getvar "plinewid"))
(setvar "plinewid" 0)
(setq oldsnap(getvar"osmode"))
(setq oldortho(getvar"orthomode"))
(initget "Single Horizonal Vertical")
(setq sele(getkword "\n部裝明細序號填寫方式[水平多項(H)/垂直多項(V)/單一序號(S)]<單一序號>:"))
(if (not sele)
(setq sele "Single")
)
(setq txt0 1)
(while (/= sele "eXit")
(initget 1)
(setvar "osmode" 0)
(setq pt_s(getpoint "\n選擇引線起點:"))
(initget 1)
(setvar "osmode" oldsnap)
(setvar "orthomode" 0)
(setq pt_m(getpoint pt_s"\n選擇序號起點:"))
(setq pt_t (polar pt_m (/ PI 2) 3.5))
(command "donut" "0" "0.5" "non" pt_s "")
(cond
((= sele "Single")
(princ (strcat"\n請輸入序號<" (itoa txt0) ">:"))
(setq txt(getint))
(if (not txt)
(setq txt txt0)
)
(setq txt0 (+ txt 1))
(if (> (car pt_m)(car pt_s))
(progn
(setq pt_c (polar pt_m PI 4))
(setq pt_e (polar pt_m 0 4))
)
(progn
(setq pt_c (polar pt_m 0 4))
(setq pt_e (polar pt_m PI 4))
)
)
(command "pline" "non" pt_s "non" pt_c "non" pt_e "")
(command "text" "m" "non" pt_t "5" "0" txt)
)
((= sele "Vertical")
(initget 1)
(setq num(getint"\n請輸入同零件組的項數:"))
(if (>(car pt_m)(car pt_s))
(progn
(setq pt_c(polar pt_m PI 4))
(setq pt_e(polar pt_m 0 4))
)
(progn
(setq pt_c(polar pt_m 0 4))
(setq pt_e(polar pt_m PI 4))
)
)
(setq tt 1)
(while(<= tt num)
(princ(strcat "\n請輸入序號<" (itoa txt0) ">:"))
(setq txt(getint))
(if (not txt)
(setq txt txt0)
)
(setq txt0 (+ txt 1))
(command "pline" "non" pt_s "non" pt_c "non" pt_e "")
(command "text" "m" "non" pt_t "5" "0" txt)
(setq pt_s pt_c)
(setq pt_c (polar pt_c (/ PI 2) 8))
(setq pt_e (polar pt_e (/ PI 2) 8))
(setq pt_t (polar pt_t (/ PI 2) 8))
(setq tt (1+ tt))
)
)
((= sele "Horizonal")
(initget 1)
(setq num(getint"\n請輸入同零件組的項數:"))
(setq pt_l(polar pt_m PI 4))
(setq pt_r(polar pt_l 0 (+(*(- num 1) 10.828) 8)))
(if (and (<(car pt_l)(car pt_s))(>(abs(- (car pt_l) (car pt_s)))(abs(-(car pt_r)(car pt_s)))))
(progn
(command "pline" "non" pt_s "non" pt_r "non" "@8<180" "")
(setq tt 1)
(while (< tt num)
(command "pline" "@" "non" "@2<-135" "non" "@2<135" "non" "@8<180" "")
(setq tt (1+ tt))
)
)
(progn
(command "pline" "non" pt_s "non" pt_l "non" "@8<0" "")
(setq tt 1)
(while(< tt num)
(command "pline" "@" "non" "@2<-45" "non" "@2<45" "non" "@8<0" "")
(setq tt(1+ tt))
)
)
)
(setq tt 1)
(while (<= tt num)
(princ (strcat "\n請輸入序號<" (itoa txt0) ">:"))
(setq txt (getint))
(if (not txt)
(setq txt txt0)
)
(setq txt0 (+ txt 1))
(command "text" "m" "non" pt_t "5" "0" txt)
(setq pt_t(polar pt_t 0 10.828))
(setq tt (1+ tt))
)
)
)
(initget "Single Horizonal Vertical eXit")
(setq sele(getkword "\n部裝明細序號填寫方式[水平多項(H)/垂直多項(V)/單一序號(S)/退出(X)]<退出>:"))
(if (not sele)
(setq sele "eXit")
)
)
(setvar "clayer" oldlayer)
(setvar "cmdecho" oldecho)
(setvar "textstyle" oldstyle)
(setvar "textsize" oldsize)
(setvar "plinewid" oldpwid)
(setvar "orthomode" oldortho)
(princ)
)
(princ"已裝載")
;;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(vl-load-com)
(defun Chg_layer (calling-reactor commandInfo / lay doc lays lay1)
(if (setq lay (cdr (assoc (car commandInfo) lay_lst)))
(progn
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq lays (vla-get-layers doc))
(setq lay1 (vl-catch-all-apply \'vla-item (list lays lay)))
(if (vl-catch-all-error-p lay1)
(setq lay1 (vla-add lays lay))
)
(vla-put-activelayer doc lay1)
)
)
(princ)
)
(defun test (lst)
(vlr-pers (vlr-command-Reactor
nil
\'((:VLR-commandWillStart . Chg_layer))
)
)
(setq lay_lst lst)
)
(setq pt2(polar pt1 (/ (* pi 7) 4) 1.41421))
(command"line" pt1 pt2 "")
(setq pt3(polar pt2 (/ pi 4) 1.41421))
(setq pt4(list (+ (car pt3) 6) (cadr pt3)))
(command"line" pt2 pt3 pt4 "")
(setq pttxt(list (+ (car pt3) 3) (+ (cadr pt) 2.4)))
(setq txt (rtos (+ (atoi txt) 1) 2 0))
(print txt)
(command "text" "MC" pttxt 3.5 0 txt)
(setq pt1 pt4)
)
(setvar "clayer" cl)
(setvar "osmode" os)
)
;;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;; 版權所有 (C) 1991-2000 明經通道 鄭立楷
;;
;; 本軟件免費可供進行任何用途需求的拷貝、修改及發行, 但請遵循下述原則:
;;
;; 1) 上列的版權通告必須出現在每一份拷貝裡。
;; 2) 相關的說明文檔也必須載有版權通告及本項許可通告。
;;
;; 本軟件僅提供作為應用上的參考, 而未聲明或隱含任何保證; 對於任何特殊
;; 用途之適應性, 以及商業銷售所隱含作出的保證, 在此一概予以否認。
;;
;; http://www.mjtd.com http://www.mccad.net
;;
;; e-mail:mccad@mjtd.com
;;
;;
(princ"\n總裝明細序號填寫程序")
(defun c:mxxh(/ oldecho oldlayer oldstyle oldsize oldpwid oldsnap oldortho
sele txto txt pt_s pt_m pt_t pt_r pt_l pt_c pt_e tt num)
(setq oldecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq oldlayer (getvar "clayer"))
(if (=(tblobjname "LAYER" "3") nil)
(progn
(entmake (list
'(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
'(6 . "CONTINUOUS")
'(62 . 3)
'(70 . 0)
(cons 2 "3")
)
)
)
)
(setvar "clayer" "3")
(setq oldstyle (getvar "textstyle"))
(setq oldsize (getvar "textsize"))
(setq oldpwid (getvar "plinewid"))
(setvar "plinewid" 0)
(setq oldsnap(getvar"osmode"))
(setq oldortho(getvar"orthomode"))
(initget "Single Horizonal Vertical")
(setq sele(getkword "\n部裝明細序號填寫方式[水平多項(H)/垂直多項(V)/單一序號(S)]<單一序號>:"))
(if (not sele)
(setq sele "Single")
)
(setq txt0 1)
(while (/= sele "eXit")
(initget 1)
(setvar "osmode" 0)
(setq pt_s(getpoint "\n選擇引線起點:"))
(initget 1)
(setvar "osmode" oldsnap)
(setvar "orthomode" 0)
(setq pt_m(getpoint pt_s"\n選擇序號起點:"))
(setq pt_t (polar pt_m (/ PI 2) 3.5))
(command "donut" "0" "0.5" "non" pt_s "")
(cond
((= sele "Single")
(princ (strcat"\n請輸入序號<" (itoa txt0) ">:"))
(setq txt(getint))
(if (not txt)
(setq txt txt0)
)
(setq txt0 (+ txt 1))
(if (> (car pt_m)(car pt_s))
(progn
(setq pt_c (polar pt_m PI 4))
(setq pt_e (polar pt_m 0 4))
)
(progn
(setq pt_c (polar pt_m 0 4))
(setq pt_e (polar pt_m PI 4))
)
)
(command "pline" "non" pt_s "non" pt_c "non" pt_e "")
(command "text" "m" "non" pt_t "5" "0" txt)
)
((= sele "Vertical")
(initget 1)
(setq num(getint"\n請輸入同零件組的項數:"))
(if (>(car pt_m)(car pt_s))
(progn
(setq pt_c(polar pt_m PI 4))
(setq pt_e(polar pt_m 0 4))
)
(progn
(setq pt_c(polar pt_m 0 4))
(setq pt_e(polar pt_m PI 4))
)
)
(setq tt 1)
(while(<= tt num)
(princ(strcat "\n請輸入序號<" (itoa txt0) ">:"))
(setq txt(getint))
(if (not txt)
(setq txt txt0)
)
(setq txt0 (+ txt 1))
(command "pline" "non" pt_s "non" pt_c "non" pt_e "")
(command "text" "m" "non" pt_t "5" "0" txt)
(setq pt_s pt_c)
(setq pt_c (polar pt_c (/ PI 2) 8))
(setq pt_e (polar pt_e (/ PI 2) 8))
(setq pt_t (polar pt_t (/ PI 2) 8))
(setq tt (1+ tt))
)
)
((= sele "Horizonal")
(initget 1)
(setq num(getint"\n請輸入同零件組的項數:"))
(setq pt_l(polar pt_m PI 4))
(setq pt_r(polar pt_l 0 (+(*(- num 1) 10.828) 8)))
(if (and (<(car pt_l)(car pt_s))(>(abs(- (car pt_l) (car pt_s)))(abs(-(car pt_r)(car pt_s)))))
(progn
(command "pline" "non" pt_s "non" pt_r "non" "@8<180" "")
(setq tt 1)
(while (< tt num)
(command "pline" "@" "non" "@2<-135" "non" "@2<135" "non" "@8<180" "")
(setq tt (1+ tt))
)
)
(progn
(command "pline" "non" pt_s "non" pt_l "non" "@8<0" "")
(setq tt 1)
(while(< tt num)
(command "pline" "@" "non" "@2<-45" "non" "@2<45" "non" "@8<0" "")
(setq tt(1+ tt))
)
)
)
(setq tt 1)
(while (<= tt num)
(princ (strcat "\n請輸入序號<" (itoa txt0) ">:"))
(setq txt (getint))
(if (not txt)
(setq txt txt0)
)
(setq txt0 (+ txt 1))
(command "text" "m" "non" pt_t "5" "0" txt)
(setq pt_t(polar pt_t 0 10.828))
(setq tt (1+ tt))
)
)
)
(initget "Single Horizonal Vertical eXit")
(setq sele(getkword "\n部裝明細序號填寫方式[水平多項(H)/垂直多項(V)/單一序號(S)/退出(X)]<退出>:"))
(if (not sele)
(setq sele "eXit")
)
)
(setvar "clayer" oldlayer)
(setvar "cmdecho" oldecho)
(setvar "textstyle" oldstyle)
(setvar "textsize" oldsize)
(setvar "plinewid" oldpwid)
(setvar "orthomode" oldortho)
(princ)
)
(princ"已裝載")
;;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(vl-load-com)
(defun Chg_layer (calling-reactor commandInfo / lay doc lays lay1)
(if (setq lay (cdr (assoc (car commandInfo) lay_lst)))
(progn
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq lays (vla-get-layers doc))
(setq lay1 (vl-catch-all-apply \'vla-item (list lays lay)))
(if (vl-catch-all-error-p lay1)
(setq lay1 (vla-add lays lay))
)
(vla-put-activelayer doc lay1)
)
)
(princ)
)
(defun test (lst)
(vlr-pers (vlr-command-Reactor
nil
\'((:VLR-commandWillStart . Chg_layer))
)
)
(setq lay_lst lst)
)
;;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun c:bii(/ n pt txt txt0 pt1 pt2 pt3 pttxt d)
(setq txt0 1)
(while (setq pt(getpoint "\\n 輸入標記線連接點: " ))
(setq n(getint" 請輸入零件數目<1>: "))
(if(not n)
(setq n 1)
)
(princ (strcat "\\n 輸入起始零件序號<" (itoa txt0) ">:"))
(setq txt(getint))
(if(not txt)
(setq txt txt0)
)
(setq d(getstring "\\n 在左還是在右<在左r>: "))
(if(= "r" d)
(setq pt(list (- (car pt) (+ (* 6 n) (* 2 (- n 1)))) (cadr pt)))
)
(defun c:bii(/ n pt txt txt0 pt1 pt2 pt3 pttxt d)
(setq txt0 1)
(while (setq pt(getpoint "\\n 輸入標記線連接點: " ))
(setq n(getint" 請輸入零件數目<1>: "))
(if(not n)
(setq n 1)
)
(princ (strcat "\\n 輸入起始零件序號<" (itoa txt0) ">:"))
(setq txt(getint))
(if(not txt)
(setq txt txt0)
)
(setq d(getstring "\\n 在左還是在右<在左r>: "))
(if(= "r" d)
(setq pt(list (- (car pt) (+ (* 6 n) (* 2 (- n 1)))) (cadr pt)))
)
(setq pt1(list (+ (car pt) 6) (cadr pt))
pttxt(list (+ (car pt) 3) (+ (cadr pt) 2.4))
)
(setq cl(getvar "clayer"))
(setq os(getvar "osmode"))
(setvar "clayer" "w文字標注")
(setvar "osmode" 0)
(command"line" pt pt1 "")
(command"text" "mc" pttxt 3.5 0 txt)
(repeat (- n 1)
(setq pt2(polar pt1 (/ (* pi 7) 4) 1.41421))
(command"line" pt1 pt2 "")
(setq pt3(list (+ (car pt1) 2) (cadr pt1)))
(setq pt4(list (+ (car pt3) 6) (cadr pt3)))
(command"line" pt2 pt3 pt4 "")
(setq pttxt(list (+ (car pt3) 3) (+ (cadr pt) 2.4)))
(setq txt (1+ txt))
(print txt)
(command "text" "MC" pttxt 3.5 0 txt)
(setq pt1 pt4)
)
(setq txt0 (+1 txt)
)
(setvar "clayer" cl)
(setvar "osmode" os)
)
;;;******************************************************************
(setq pt2(polar pt1 (/ (* pi 7) 4) 1.41421))
(command"line" pt1 pt2 "")
(setq pt3(list (+ (car pt1) 2) (cadr pt1)))
(setq pt4(list (+ (car pt3) 6) (cadr pt3)))
(command"line" pt2 pt3 pt4 "")
(setq pttxt(list (+ (car pt3) 3) (+ (cadr pt) 2.4)))
(setq txt (1+ txt))
(print txt)
(command "text" "MC" pttxt 3.5 0 txt)
(setq pt1 pt4)
)
(setq txt0 (+1 txt)
)
(setvar "clayer" cl)
(setvar "osmode" os)
)
;;;******************************************************************
//計算多邊形的形心坐標
BOOL GetPolyCentroid(AcDbPolyline * pPline, ads_point CenPt)
{
unsigned int i, iCount = 0;
AcDbVoidPtrArray curveSegments, regions;
AcGePoint3d LinePt0, LinePt1;
AcGePoint3d origin;
AcGeVector3d xAxis, yAxis;
double perimeter, area, prodInertia;
double momInertia[2], prinMoments[2], radiiGyration[2];
AcGePoint2d centroid;
AcGeVector2d prinAxes[2];
AcGePoint2d extentsLow, extentsHigh;
if (pPline->isClosed() != Adesk::kTrue) {
ads_printf("\n折線不封閉, 無法形成正確的區域。");
return FALSE;
}
curveSegments.append((AcDbCurve *) pPline);
if (AcDbRegion::createFromCurves(curveSegments, regions) != Acad::eOk){
ads_printf("\n創建臨時區域對像失敗!");
//清除Region, 應第9 貼的指點,即使createFromCurves錯誤,也應清除之;
iCount = regions.length();
for(i = 0; i < iCount; i++)
delete (AcDbRegion *)regions.at(i);
return FALSE;
}
AcDbRegion * pRegion;
if ((iCount = regions.length()) == 0){
ads_printf("\n創建臨時區域對像為空!");
return FALSE;
}
if (iCount > 1){
// 多個 AcDbRegion , 無法確定應該返回哪一個,乾脆返回NULL;
ads_printf("\n多個區域實體。");
for(i = 0; i < iCount; i++)
delete (AcDbRegion *)regions.at(i);
return FALSE;
}
pRegion = (AcDbRegion *) regions.at(0);
origin.set(0,0,0); //設置原點坐標
xAxis.set(1,0,0); //設置X Y軸,
yAxis.set(0,1,0);
if (pRegion->getAreaProp(
origin, xAxis, yAxis,
perimeter, area, centroid, momInertia, prodInertia, prinMoments, prinAxes, radiiGyration,
extentsLow, extentsHigh) != Acad::eOk ){
ads_printf("\n區域面積: %.3f, 周長:%.3f", area, perimeter);
ads_printf("\n獲取區域對像屬性失敗!");
delete pRegion;
return FALSE;
}
XYZ_POINT(CenPt, centroid.x, centroid.y, 0); //得到形心坐標
ads_printf("\n區域面積: %.3f, 周長:%.3f", area, perimeter);
pRegion->close();
delete pRegion;
return TRUE;
}
BOOL GetPolyCentroid(AcDbPolyline * pPline, ads_point CenPt)
{
unsigned int i, iCount = 0;
AcDbVoidPtrArray curveSegments, regions;
AcGePoint3d LinePt0, LinePt1;
AcGePoint3d origin;
AcGeVector3d xAxis, yAxis;
double perimeter, area, prodInertia;
double momInertia[2], prinMoments[2], radiiGyration[2];
AcGePoint2d centroid;
AcGeVector2d prinAxes[2];
AcGePoint2d extentsLow, extentsHigh;
if (pPline->isClosed() != Adesk::kTrue) {
ads_printf("\n折線不封閉, 無法形成正確的區域。");
return FALSE;
}
curveSegments.append((AcDbCurve *) pPline);
if (AcDbRegion::createFromCurves(curveSegments, regions) != Acad::eOk){
ads_printf("\n創建臨時區域對像失敗!");
//清除Region, 應第9 貼的指點,即使createFromCurves錯誤,也應清除之;
iCount = regions.length();
for(i = 0; i < iCount; i++)
delete (AcDbRegion *)regions.at(i);
return FALSE;
}
AcDbRegion * pRegion;
if ((iCount = regions.length()) == 0){
ads_printf("\n創建臨時區域對像為空!");
return FALSE;
}
if (iCount > 1){
// 多個 AcDbRegion , 無法確定應該返回哪一個,乾脆返回NULL;
ads_printf("\n多個區域實體。");
for(i = 0; i < iCount; i++)
delete (AcDbRegion *)regions.at(i);
return FALSE;
}
pRegion = (AcDbRegion *) regions.at(0);
origin.set(0,0,0); //設置原點坐標
xAxis.set(1,0,0); //設置X Y軸,
yAxis.set(0,1,0);
if (pRegion->getAreaProp(
origin, xAxis, yAxis,
perimeter, area, centroid, momInertia, prodInertia, prinMoments, prinAxes, radiiGyration,
extentsLow, extentsHigh) != Acad::eOk ){
ads_printf("\n區域面積: %.3f, 周長:%.3f", area, perimeter);
ads_printf("\n獲取區域對像屬性失敗!");
delete pRegion;
return FALSE;
}
XYZ_POINT(CenPt, centroid.x, centroid.y, 0); //得到形心坐標
ads_printf("\n區域面積: %.3f, 周長:%.3f", area, perimeter);
pRegion->close();
delete pRegion;
return TRUE;
}
//添加擴展數據
//實體添加擴展數據(字符串)
bool AddXData(CString appName, AcDbObjectId entId,CString data)
{
//open entity for read
AcDbEntity*pEnt;
Acad::ErrorStatus es=acdbOpenAcDbEntity(pEnt,entId,AcDb::kForRead);
if(es!=Acad::eOk)
{
ads_printf("error in open entity\n");
return false;
}
//get XData buffer
struct resbuf*pRb,*pTemp;
pRb=pEnt->xData(appName);
if(pRb!=NULL)//have XData
{
//pTemp移到表尾
pTemp=pRb;
for(pTemp=pRb;pTemp->rbnext!=NULL;pTemp=pTemp->rbnext){;}
}
else//NOT have XData
{
//create new xData
ads_regapp(appName);
pRb=ads_newrb(AcDb::kDxfRegAppName);
pRb->resval.rstring=(char*)malloc(appName.GetLength()+1);
strcpy(pRb->resval.rstring,appName);
pTemp=pRb;
}
//fill xData string
pTemp->rbnext=ads_newrb(AcDb::kDxfXdAsciiString);
pTemp=pTemp->rbnext;
pTemp->resval.rstring=(char*)malloc(data.GetLength()+1);
strcpy(pTemp->resval.rstring,data);
//add xData
es=pEnt->upgradeOpen();
if(es!=Acad::eOk)
{
ads_printf("\nError occur in updateOpen.");
pEnt->close();
ads_relrb(pRb);
return false;
}
es=pEnt->setXData(pRb);
if(es!=Acad::eOk)
{
ads_printf("\nError occur in setXData.");
pEnt->close();
ads_relrb(pRb);
return false;
}
//
pEnt->close();
ads_relrb(pRb);
return true;
}
//發命令前加按了兩個ESCAPE
void SendCommand(char *cmd)
{
HWND wnd;
char cp[3];
wnd = adsw_acadMainWnd();
if(!wnd) return;
COPYDATASTRUCT cmddata;
cp[0] = VK_ESCAPE;
cp[1] = VK_ESCAPE;
cp[2] = NULL;
cmddata.dwData = (DWORD)1;
cmddata.cbData = (DWORD)strlen(cp)+1;
cmddata.lpData = cp;
SendMessage(wnd,WM_COPYDATA,(WPARAM)cp,(LPARAM)&cmddata);
cmddata.dwData = (DWORD)1;
cmddata.cbData = (DWORD)strlen(cmd)+1;
cmddata.lpData = cmd;
SendMessage(wnd,WM_COPYDATA,(WPARAM)wnd,(LPARAM)&cmddata);
}
//函數功能:根據用戶指定的兩點,自動創建破斷線
void CAD_EXTBreakLine()
{
acutPrintf("指定兩點,自動創建折線破斷線\n");
ads_point StartPoint,EndPoint;
if(acedGetPoint(NULL,"\n請指定破斷線的起點:",StartPoint)!=RTNORM) return;
if(acedGetPoint(StartPoint,"\n請指定破斷線的終點:",EndPoint)!=RTNORM) return;
AcGePoint3d Start,End;
End = AcGePoint3d(EndPoint[X],EndPoint[Y],0);
Start = AcGePoint3d(StartPoint[X],StartPoint[Y],0);
float Length = Start.distanceTo(End);
AcGeVector3d Normal = End-Start;
Normal = Normal.normal(AcGeContext::gTol);
AcGePoint3d Point1(Start-Length*Normal*0.15);
AcGePoint3d Point2(Start+Length*Normal*0.45);
AcGePoint3d Point5(End-Length*Normal*0.45);
AcGePoint3d Point6(End+Length*Normal*0.15);
AcGeVector3d Normal2(-Normal.y,Normal.x,0);
AcGePoint3d Point3(Start+Length*Normal*0.5+Length*Normal2*0.10);
AcGePoint3d Point4(Start+Length*Normal*0.5-Length*Normal2*0.10);
AcGePoint3dArray vertices;
vertices.append(Point1);
vertices.append(Point2);
vertices.append(Point3);
vertices.append(Point4);
vertices.append(Point5);
vertices.append(Point6);
AddNewLayer("COMMANTARY");
AcDb2dPolyline* pBreakLine = new AcDb2dPolyline
(AcDb::k2dSimplePoly,vertices,0,Adesk::kTrue,0,0,NULL);
pBreakLine->setLayer("COMMANTARY",TRUE);
AcGeMatrix3d mat;
acdbUcsMatrix(mat,acdbHostApplicationServices()->workingDatabase());
pBreakLine->transformBy(mat);
pBreakLine->makeOpen();
AddEntityToDb(pBreakLine);
}
//******************生成回轉體**********************
/* pt -- 旋轉基點
ver -- 旋轉軸
angle -- 旋轉角度(角度制)
注意: 旋轉軸不能垂直於面域平面、不能穿過面域*/
//**************************************************
void CreatRevolve(AcDbObjectId entid,
AcGeVector3d normal,
AcGePoint3d pt,
AcGeVector3d ver,
double angle)
{
Acad::ErrorStatus es;
AcDbCurve *curve;
AcDbObjectId tm;
if (acdbOpenObject(curve,entid,AcDb::kForWrite)!=Acad::eOk)
{
acutPrintf("打開實體失敗!");
return ;
}
AcDbVoidPtrArray lines,regions1;
lines.append((void*)curve);
curve->close();
es = AcDbRegion::createFromCurves(lines,regions1);
if(es != Acad::eOk)
{
acutPrintf("獲得面域失敗!");
return ;
}
angle = angle*PI/180;
AcDbRegion *pregion1=AcDbRegion::cast((AcRxObject*)regions1[0]);
AcDb3dSolid *p3dobj = new AcDb3dSolid;
es = p3dobj->revolve(pregion1,pt,ver,angle);
if (es != Acad::eOk)
{
acutPrintf("建立回轉體失敗!請檢查回轉軸和基準點是否正確!");
}
pBlockTableRecord->appendAcDbEntity(tm,p3dobj);
p3dobj->close();
delete pregion1;
}
在ObjectARX 實現 Command 的 *Cancel* 功能: (類似 AutoLISP 中的 ^C)
acedCommand(0); // 就可以了
例如:
acedCommand (RTSTR, "dim1", RTSTR, "leader", RTSTR, "0,0", RTSTR, "10,10", 0);
acedCommand (0);
//複製對像
void cloneSameOwnerObjects()
{
// Step 1: Obtain the set of objects to be cloned.
ads_name sset;
if (acedSSGet(NULL, NULL, NULL, NULL, sset) != RTNORM) {
acutPrintf("\nNothing selected");
return;
}
// Step 2: Add obtained object IDs to list of objects
// to be cloned.
long length;
acedSSLength(sset, &length);
AcDbObjectIdArray objList;
AcDbObjectId ownerId = AcDbObjectId::kNull;
for (int i = 0; i < length; i++) {
ads_name ent;
acedSSName(sset, i, ent);
AcDbObjectId objId;
acdbGetObjectId(objId, ent);
// Check to be sure this has the same owner as the first
// object.
//
AcDbObject *pObj;
acdbOpenObject(pObj, objId, AcDb::kForRead);
if (pObj->ownerId() == ownerId)
objList.append(objId);
else if (i == 0) {
ownerId = pObj->ownerId();
objList.append(objId);
}
pObj->close();
}
acedSSFree(sset);
// Step 3: Get the object ID of the desired owner for
// the cloned objects. We'll use model space for
// this example.
//
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbObjectId modelSpaceId;
pBlockTable->getAt(ACDB_MODEL_SPACE, modelSpaceId);
pBlockTable->close();
// Step 4: Create a new ID map.
//
AcDbIdMapping idMap;
// Step 5: Call deepCloneObjects().
//
acdbHostApplicationServices()->workingDatabase()
->deepCloneObjects(objList, modelSpaceId, idMap);
// Now we can go through the ID map and do whatever we'd
// like to the original and/or clone objects.
//
// For this example, we'll print out the object IDs of
// the new objects resulting from the cloning process.
//
AcDbIdMappingIter iter(idMap);
for (iter.start(); !iter.done(); iter.next()) {
AcDbIdPair idPair;
iter.getMap(idPair);
if (!idPair.isCloned())
continue;
acutPrintf("\nObjectId is: %Ld",
idPair.value().asOldId());
}
}
void selObj()
{
#ifdef OARXWIZDEBUG
acutPrintf ("\nOARXWIZDEBUG - caditdellayObjdellayObj() called.");
//實體添加擴展數據(字符串)
bool AddXData(CString appName, AcDbObjectId entId,CString data)
{
//open entity for read
AcDbEntity*pEnt;
Acad::ErrorStatus es=acdbOpenAcDbEntity(pEnt,entId,AcDb::kForRead);
if(es!=Acad::eOk)
{
ads_printf("error in open entity\n");
return false;
}
//get XData buffer
struct resbuf*pRb,*pTemp;
pRb=pEnt->xData(appName);
if(pRb!=NULL)//have XData
{
//pTemp移到表尾
pTemp=pRb;
for(pTemp=pRb;pTemp->rbnext!=NULL;pTemp=pTemp->rbnext){;}
}
else//NOT have XData
{
//create new xData
ads_regapp(appName);
pRb=ads_newrb(AcDb::kDxfRegAppName);
pRb->resval.rstring=(char*)malloc(appName.GetLength()+1);
strcpy(pRb->resval.rstring,appName);
pTemp=pRb;
}
//fill xData string
pTemp->rbnext=ads_newrb(AcDb::kDxfXdAsciiString);
pTemp=pTemp->rbnext;
pTemp->resval.rstring=(char*)malloc(data.GetLength()+1);
strcpy(pTemp->resval.rstring,data);
//add xData
es=pEnt->upgradeOpen();
if(es!=Acad::eOk)
{
ads_printf("\nError occur in updateOpen.");
pEnt->close();
ads_relrb(pRb);
return false;
}
es=pEnt->setXData(pRb);
if(es!=Acad::eOk)
{
ads_printf("\nError occur in setXData.");
pEnt->close();
ads_relrb(pRb);
return false;
}
//
pEnt->close();
ads_relrb(pRb);
return true;
}
//發命令前加按了兩個ESCAPE
void SendCommand(char *cmd)
{
HWND wnd;
char cp[3];
wnd = adsw_acadMainWnd();
if(!wnd) return;
COPYDATASTRUCT cmddata;
cp[0] = VK_ESCAPE;
cp[1] = VK_ESCAPE;
cp[2] = NULL;
cmddata.dwData = (DWORD)1;
cmddata.cbData = (DWORD)strlen(cp)+1;
cmddata.lpData = cp;
SendMessage(wnd,WM_COPYDATA,(WPARAM)cp,(LPARAM)&cmddata);
cmddata.dwData = (DWORD)1;
cmddata.cbData = (DWORD)strlen(cmd)+1;
cmddata.lpData = cmd;
SendMessage(wnd,WM_COPYDATA,(WPARAM)wnd,(LPARAM)&cmddata);
}
//函數功能:根據用戶指定的兩點,自動創建破斷線
void CAD_EXTBreakLine()
{
acutPrintf("指定兩點,自動創建折線破斷線\n");
ads_point StartPoint,EndPoint;
if(acedGetPoint(NULL,"\n請指定破斷線的起點:",StartPoint)!=RTNORM) return;
if(acedGetPoint(StartPoint,"\n請指定破斷線的終點:",EndPoint)!=RTNORM) return;
AcGePoint3d Start,End;
End = AcGePoint3d(EndPoint[X],EndPoint[Y],0);
Start = AcGePoint3d(StartPoint[X],StartPoint[Y],0);
float Length = Start.distanceTo(End);
AcGeVector3d Normal = End-Start;
Normal = Normal.normal(AcGeContext::gTol);
AcGePoint3d Point1(Start-Length*Normal*0.15);
AcGePoint3d Point2(Start+Length*Normal*0.45);
AcGePoint3d Point5(End-Length*Normal*0.45);
AcGePoint3d Point6(End+Length*Normal*0.15);
AcGeVector3d Normal2(-Normal.y,Normal.x,0);
AcGePoint3d Point3(Start+Length*Normal*0.5+Length*Normal2*0.10);
AcGePoint3d Point4(Start+Length*Normal*0.5-Length*Normal2*0.10);
AcGePoint3dArray vertices;
vertices.append(Point1);
vertices.append(Point2);
vertices.append(Point3);
vertices.append(Point4);
vertices.append(Point5);
vertices.append(Point6);
AddNewLayer("COMMANTARY");
AcDb2dPolyline* pBreakLine = new AcDb2dPolyline
(AcDb::k2dSimplePoly,vertices,0,Adesk::kTrue,0,0,NULL);
pBreakLine->setLayer("COMMANTARY",TRUE);
AcGeMatrix3d mat;
acdbUcsMatrix(mat,acdbHostApplicationServices()->workingDatabase());
pBreakLine->transformBy(mat);
pBreakLine->makeOpen();
AddEntityToDb(pBreakLine);
}
//******************生成回轉體**********************
/* pt -- 旋轉基點
ver -- 旋轉軸
angle -- 旋轉角度(角度制)
注意: 旋轉軸不能垂直於面域平面、不能穿過面域*/
//**************************************************
void CreatRevolve(AcDbObjectId entid,
AcGeVector3d normal,
AcGePoint3d pt,
AcGeVector3d ver,
double angle)
{
Acad::ErrorStatus es;
AcDbCurve *curve;
AcDbObjectId tm;
if (acdbOpenObject(curve,entid,AcDb::kForWrite)!=Acad::eOk)
{
acutPrintf("打開實體失敗!");
return ;
}
AcDbVoidPtrArray lines,regions1;
lines.append((void*)curve);
curve->close();
es = AcDbRegion::createFromCurves(lines,regions1);
if(es != Acad::eOk)
{
acutPrintf("獲得面域失敗!");
return ;
}
angle = angle*PI/180;
AcDbRegion *pregion1=AcDbRegion::cast((AcRxObject*)regions1[0]);
AcDb3dSolid *p3dobj = new AcDb3dSolid;
es = p3dobj->revolve(pregion1,pt,ver,angle);
if (es != Acad::eOk)
{
acutPrintf("建立回轉體失敗!請檢查回轉軸和基準點是否正確!");
}
pBlockTableRecord->appendAcDbEntity(tm,p3dobj);
p3dobj->close();
delete pregion1;
}
在ObjectARX 實現 Command 的 *Cancel* 功能: (類似 AutoLISP 中的 ^C)
acedCommand(0); // 就可以了
例如:
acedCommand (RTSTR, "dim1", RTSTR, "leader", RTSTR, "0,0", RTSTR, "10,10", 0);
acedCommand (0);
//複製對像
void cloneSameOwnerObjects()
{
// Step 1: Obtain the set of objects to be cloned.
ads_name sset;
if (acedSSGet(NULL, NULL, NULL, NULL, sset) != RTNORM) {
acutPrintf("\nNothing selected");
return;
}
// Step 2: Add obtained object IDs to list of objects
// to be cloned.
long length;
acedSSLength(sset, &length);
AcDbObjectIdArray objList;
AcDbObjectId ownerId = AcDbObjectId::kNull;
for (int i = 0; i < length; i++) {
ads_name ent;
acedSSName(sset, i, ent);
AcDbObjectId objId;
acdbGetObjectId(objId, ent);
// Check to be sure this has the same owner as the first
// object.
//
AcDbObject *pObj;
acdbOpenObject(pObj, objId, AcDb::kForRead);
if (pObj->ownerId() == ownerId)
objList.append(objId);
else if (i == 0) {
ownerId = pObj->ownerId();
objList.append(objId);
}
pObj->close();
}
acedSSFree(sset);
// Step 3: Get the object ID of the desired owner for
// the cloned objects. We'll use model space for
// this example.
//
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbObjectId modelSpaceId;
pBlockTable->getAt(ACDB_MODEL_SPACE, modelSpaceId);
pBlockTable->close();
// Step 4: Create a new ID map.
//
AcDbIdMapping idMap;
// Step 5: Call deepCloneObjects().
//
acdbHostApplicationServices()->workingDatabase()
->deepCloneObjects(objList, modelSpaceId, idMap);
// Now we can go through the ID map and do whatever we'd
// like to the original and/or clone objects.
//
// For this example, we'll print out the object IDs of
// the new objects resulting from the cloning process.
//
AcDbIdMappingIter iter(idMap);
for (iter.start(); !iter.done(); iter.next()) {
AcDbIdPair idPair;
iter.getMap(idPair);
if (!idPair.isCloned())
continue;
acutPrintf("\nObjectId is: %Ld",
idPair.value().asOldId());
}
}
void selObj()
{
#ifdef OARXWIZDEBUG
acutPrintf ("\nOARXWIZDEBUG - caditdellayObjdellayObj() called.");