TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: vnanhvu on June 06, 2011, 02:38:53 AM
-
When I Work With Layout. I Use Command Mview For Create A Viewport. I Use This Lisp To Modify Scale Viewport By Click On Frame Viewport. But When I Use Command Mview>object And Click Object Ex.:cirlce Or Rectang, My Lisp No Value. Thank For All
THANK FOR ALL(defun c:WQQ(/ ent dz Viewport newVal)
(if (/= (getvar "cvport") 1)
(alert "\nChi co the chay tren khong gian giay (Layout).")
(progn
(while
(not (and
(setq ent (car (entsel "\nChon Viewport : ")))
(if ent (= (cdr (assoc 0 (entget ent))) "VIEWPORT") )
)
)
(princ "\nkhong phai Viewport. Chon lai : ")
)
(setq dz (getvar "dimzin"))
(setvar "dimzin" 8 )
(setq Viewport (vlax-Ename->Vla-Object ent)
newVal (GetScale (getstring(strcat "\nNhap Scale Standard (vd. 1/50, 1:50, 50 ) <" ( getvport_scale Viewport)"> :")) ))
(if newVal (vla-put-CustomScale Viewport newVal))
(setvar "dimzin" dz )
)
)
(princ)
)
(defun GetScale (Str / Sc)
(cond
((/= (type Str) 'STR) nil)
((or (setq Pos (vl-string-search ":" Str))(setq Pos (vl-string-search "/" Str)))
(setq Sc (vl-catch-all-apply
'(lambda () (/ (distof (substr Str 1 Pos)) (distof (substr Str (+ 2 Pos)))) ) ) ) )
((setq Sc (vl-catch-all-apply '(lambda () (/ 1 (distof Str))))))
)
(if (vl-catch-all-error-p Sc)
(setq Sc nil)
)
Sc
)
(defun getvport_scale (viewport / sc csc)
(setq sc (vla-get-StandardScale viewport))
(cond
((= sc acVpScaleToFit)
(setq csc 1.0)
)
((= sc acVpCustomScale)
(setq csc (/ 1 (vla-get-CustomScale viewport)))
(if (= csc 0.0) (setq csc 1.0))
)
((= sc acVp1_128in_1ft) (setq csc 1536.0))
((= sc acVp1_64in_1ft) (setq csc 768.0))
((= sc acVp1_32in_1ft) (setq csc 384.0))
((= sc acVp1_16in_1ft) (setq csc 192.0))
((= sc acVp3_32in_1ft) (setq csc 128.0))
((= sc acVp1_8in_1ft) (setq csc 96.0))
((= sc acVp3_16in_1ft)(setq csc 64.0))
((= sc acVp1_4in_1ft) (setq csc 48.0))
((= sc acVp3_8in_1ft) (setq csc 32.0))
((= sc acVp1_2in_1ft) (setq csc 24.0))
((= sc acVp3_4in_1ft) (setq csc 16.0))
((= sc acVp1in_1ft) (setq csc 12.0))
((= sc acVp3in_1ft)(setq csc 4.0))
((= sc acVp6in_1ft)(setq csc 2.0))
((= sc acVp1ft_1ft)(setq csc 1.0))
((= sc acVp1_1) (setq csc 1.0))
((= sc acVp1_2) (setq csc 2.0))
((= sc acVp1_4) (setq csc 4.0))
((= sc acVp1_8) (setq csc 8.0))
((= sc acVp1_10) (setq csc 10.0))
((= sc acVp1_16) (setq csc 16.0))
((= sc acVp1_20) (setq csc 20.0))
((= sc acVp1_30) (setq csc 30.0))
((= sc acVp1_40) (setq csc 40.0))
((= sc acVp1_50) (setq csc 50.0))
((= sc acVp1_100)(setq csc 100.0))
((= sc acVp2_1) (setq csc 0.5))
((= sc acVp4_1) (setq csc 0.25))
((= sc acVp8_1) (setq csc 0.125))
((= sc acVp10_1) (setq csc 0.1))
((= sc acVp100_1) (setq csc 0.01))
)
(if (member (getvar "lunits") '(1 2 3 5))
(strcat "1:" (rtos csc ))
(strcat (rtos (/ 12 csc) 4 5) "=" (rtos 12 4))
)
)
-
Check this out ..... although the Viewports toolbar would do the trick easily .
(defun c:Test (/ vp sc)(vl-load-com)
; Tharwat 06. 06. 2011
(if (and (setq vp (ssget "_:L" '((0 . "VIEWPORT"))))
(setq sc (getdist "\n Enter scale factor for Viewport :"))
)
(vla-put-CustomScale (vlax-ename->vla-object (ssname vp 0)) sc)
(princ)
)
(princ)
)
Tharwat
-
hi Tharwat!
can you explain for me a question, i happy if you help.
when i use dimension annotative style, with your lisp , my viewport is value, but dim not display. it appear only i click viewport toolbar. Why, i dont understand. What way fit ? ( ex.: i use dim annotative 1/50. it display only in viewport 1/50.BUt i use your lisp with 1/50 viewport, viewport change into 1/50 without dim. it only display when i click viewport toolbar 1/50 )
Thanks again.
-
I did not get your point , but if you that does not help with annotative dims , you can play with it through the Annotative Scale list .
-
You have to look for assoc 330 to get the viewport created from an object. Perhaps this will get you pointed in the right direction:
(defun getvport (/ e)
(if (setq e (car (entsel)))
(cond ((eq (cdr (assoc 0 (entget e))) "VIEWPORT") e)
((and (setq e (cdr (assoc 330 (entget e)))) (eq (cdr (assoc 0 (entget e))) "VIEWPORT")) e)
)
)
)
(getvport)