|
分享一个来自国外网站的好东西功能强大
< 3D实体展平为各视图角的2D图块(Block)>
执行指令:fse
(1)提取3D物体如图1选测试图的3D马达
(2)出现询问各视图角度是否创建为2D块都选确定如图2
(3)如图3会在3D沉水马达物体右上方出现转换好的各种视角的2D图块
初次在AutoCAD2018测试OK
[code]
;;*******************************************************************
;;
;;<3D solids flattened into 2D BLOCK for each view angle>
;;Execute command:FSE
;;
;;*******************************************************************
;--------------------------------------------------------------------
(vl-load-com)
(or kglobal:acadapp (setq kglobal:acadapp (vlax-get-acad-object)))
(or kglobal:activedoc
(setq kglobal:activedoc (vla-get-activedocument kglobal:acadapp))
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(defun c:fse () (c:Flatshot_Selection_ALLVIEWS))
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(defun c:FLATSHOT_SELECTION_ALLVIEWS (/ *error*
;;
ss_Solids ss1 ent_List HideObjList
wp marker flatblock
)
;;-----------------------------------------------------------
;|
* https://www.theswamp.org/index.php?topic=33105.0
* CodeHimBelonga kwbrown 2010.04.21
* c:Flatshot_Selection_ALLVIEWS
* Routine to CREATE 2D representation of all SELECTED 3D SOLID objects
* in the current view ... or blocks containing solids.
*
*
* EDITED ON THE 27.09.2018 by 3dwannab
* Added the ability to output all the Orthographic views required to, let's say, make a dymic block out of.
* It's actually quicker doing it this way than downloading the 2D cad files.
* It renames the blocks like so: _FLATSHOT_TOP, _FLATSHOT_BOTTOM, _FLATSHOT_LEFT, _FLATSHOT_RIGHT, _FLATSHOT_BACK, _FLATSHOT_FRONT
* I tried to use a fn from Lee Mac to press the C or ENTER key for the dialog but couldn't get it to work.
* Just keep pressing create until your done.
|;;;-----------------------------------------------------------
(defun *error* (msg) (kdub:on-error msg) (princ))
;;-----------------------------------------------------------
(vla-endundomark kglobal:activedoc) ;close open group
(vla-startundomark kglobal:activedoc) ;start new group
;;-----------------------------------------------------------
(kdub:savesysvar '(("CMDECHO" 0)
("OSMODE" 0)
("expert" 5)
("SNAPANG" 0.00)
("SNAPMODE" 0)
("ORTHOMODE" 1)
("PICKADD" 1)
("PICKBOX" 5)
("INSUNITS" 0)
;; ("BLIPMODE" 1)
;; ("CLAYER")
("SORTENTS" 1)
)
)
;;----------------------------------------------------------
;; MAIN
;;-----------------------------------------------------------
(Prompt "\nSelect solids to process: ")
(if (and (setq ss_Solids (SSGET "X" (list (cons 0 "3DSOLID,INSERT"))))
(setq ss1 (SSGET (list (cons 0 "3DSOLID,INSERT"))))
(setq ent_List (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1))))
)
(progn (foreach ent ent_List (ssdel ent ss_Solids))
(setq HideObjList (mapcar 'vlax-ename->vla-object
(mapcar 'cadr (ssnamex ss_Solids))
)
wp (getvar "VIEWCTR")
marker (kdub:MarkLastEnt)
)
(foreach obj HideObjList (vla-Put-Visible obj :vlax-false))
; Top view
(command "dview" "" "point" '(0.0 0.0 0.0) '(0.0 0.0 100.0) "")
(vl-cmdf "._FlatShot" wp "" "" "")
(command "_.rename" "_B" (_BlockEffectiveName) (strcat "_FLATSHOT_TOP"))
; Bottom view
(command "dview" "" "point" '(0.0 0.0 100.0) '(0.0 0.0 0.0) "")
(vl-cmdf "._FlatShot" wp "" "" "")
(command "_.rename" "_B" (_BlockEffectiveName) (strcat "_FLATSHOT_BOTTOM"))
; Left view
(command "dview" "" "point" '(100.0 0.0 0.0) '(0.0 0.0 0.0) "")
(vl-cmdf "._FlatShot" wp "" "" "")
(command "_.rename" "_B" (_BlockEffectiveName) (strcat "_FLATSHOT_LEFT"))
; Right view
(command "dview" "" "point" '(0.0 0.0 0.0) '(100.0 0.0 0.0) "")
(vl-cmdf "._FlatShot" wp "" "" "")
(command "_.rename" "_B" (_BlockEffectiveName) (strcat "_FLATSHOT_RIGHT"))
; Back view
(command "dview" "" "point" '(0.0 0.0 0.0) '(0.0 100.0 0.0) "")
(vl-cmdf "._FlatShot" wp "" "" "")
(command "_.rename" "_B" (_BlockEffectiveName) (strcat "_FLATSHOT_BACK"))
; Front view
(command "dview" "" "point" '(0.0 100.0 0.0) '(0.0 0.0 0.0) "")
(vl-cmdf "._FlatShot" wp "" "" "")
(command "_.rename" "_B" (_BlockEffectiveName) (strcat "_FLATSHOT_FRONT"))
(foreach obj HideObjList (vla-Put-Visible obj :vlax-true))
)
)
(if (setq flatblock (kdub:ss-AfterMarkerEnt marker))
; Reset to Top view
(command "dview" "" "point" '(0.0 0.0 0.0) '(0.0 0.0 100.0) "")
)
(kdub:restoresysvar)
(princ)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;
;; LIBRARY STUFF
;;
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
(defun kdub:on-error (msg / tmp)
;;----- Cancel any Active Commands -----------------------------
(while (< 0 (getvar "cmdactive")) (command))
(setvar "menuecho" 1)
(vla-endundomark kglobal:activedoc)
;;----- Display error message if applicable _-------------------
(cond
((not msg)) ; no error, do nothing.
((member (strcase msg t) ; User cancelled.
'("console break" "function cancelled" "quit / exit abort")
)
)
((princ (strcat "\nApplication Error: " (itoa (getvar "errno")) " :- " msg))
;;----- Display backtrace if in debug mode ---------------------
(if kglobal:debug_on
(vl-bt)
)
)
)
(setvar "errno" 0)
;;----- Reset System Variables from global list ----------------
(kdub:restoresysvar)
(princ)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;; change sysvar value and save its previous value
(defun kdub:savesysvar (vars_list)
(foreach item vars_list
(setq kglobal:sysvarlist (cons (list (car item) (getvar (car item)))
kglobal:sysvarlist
)
)
(if (cadr item)
(setvar (car item) (eval (cadr item)))
)
)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(defun kdub:restoresysvar ()
(foreach item kglobal:sysvarlist (setvar (car item) (cadr item)))
(setq kglobal:sysvarlist nil)
(princ)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(defun kdub:MarkLastEnt (/ ename returnval)
(and (setq returnval (entlast))
(while (setq ename (entnext returnval)) (setq returnval ename))
)
returnval
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(defun kdub:ss-AfterMarkerEnt (ename / enext ss)
(cond ((not ename) (ssget "_X"))
((setq enext (entnext ename))
(setq ss (ssadd enext))
(while (setq enext (entnext enext))
(if (entget enext)
(ssadd enext ss)
)
)
ss
)
)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(defun _BlockEffectiveName ()
(setq
blk (entget (entlast))
ent (_dxf -1 blk)
blkpt (_dxf 10 blk)
obj (vlax-ename->vla-object ent)
blkn (vla-get-effectivename obj)
)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
;; _dxf
;; Finds the association pair, strips 1st element
;; args - dxfcode elist
;; Example - (_dxf -1 (entget (ssname (ssget) 0)))
;; Returns - <Entity name: xxxxxxxxxxx>
(defun _dxf (code elist)
(cdr (assoc code elist))
)
(princ)
(c:Flatshot_Selection_ALLVIEWS)
;|?Visual LISP? Format Options?
(80 2 45 2 nil "end of " 80 70 0 0 0 nil nil nil T)
;*** DO NOT add text below the comment! ***|;
[/code] |
|