明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 976|回复: 5

有没有比这个更好用的程序啊

[复制链接]
发表于 2020-7-3 15:59 | 显示全部楼层 |阅读模式
1明经币
  1. (defun c:CC3 ( / *error* *acad* doc ps osm as om emode pmode offd
  2.                elev locked typ typlst e d notclosed splinetyp
  3.                i o intpts lst sc minpt maxpt hidelst dellst
  4.                offsetename offsetobj trimename trimobj curcoord
  5.                mark postlst coord reg selfinter ext UCSpkpt
  6.                UCStrimobjpts WCStrimobjpts delother side
  7.                ssinside ssall sscross ssoutside ssintersect  
  8.                solidflag solidans solidlst sskeep sstest testename
  9.                WCSoffsetobjpts UCSoffsetobjpts
  10.                CC:GetScreenCoords CC:TraceObject CC:GetInters
  11.                CC:SpinBar CC:AfterEnt CC:CommandExplode
  12.                CC:ExpNestedBlock CC:FirstLastPts CC:GetBlock
  13.                CC:AttributesToText CC:UniformScale
  14.                CC:SSVLAList CC:Inside CC:UnlockLayers
  15.                CC:RelockLayers CC:ZoomToPointList Extents)
  16.   (defun *error* (msg)
  17.     (cond
  18.       ((not msg))
  19.       ((wcmatch (strcase msg) "*QUIT*,*CANCEL*"))
  20.       (T (princ (strcat "\nError: " msg)))
  21.     )
  22.     (setvar "pickstyle" ps)
  23.     (setvar "osmode" osm)
  24.     (setvar "autosnap" as)
  25.     (setvar "edgemode" emode)
  26.     (setvar "projmode" pmode)
  27.     (setvar "orthomode" om)
  28.     (setvar "elevation" elev)
  29.     (setvar "offsetdist" offd)
  30.     (setvar "cmdecho" 1)
  31.     (if (and offsetobj (not (vlax-erased-p offsetobj)))
  32.       (vla-delete offsetobj)
  33.     )
  34.     (if testename (entdel testename))
  35.     (foreach x hidelst
  36.       (if (not (vlax-erased-p x))
  37.         (vlax-put x 'Visible acTrue)
  38.       )
  39.     )
  40.     (if (and trimobj (not (vlax-erased-p trimobj)))
  41.       (vla-highlight trimobj acFalse)
  42.     )
  43.     (CC:RelockLayers locked)
  44.     (vla-EndUndoMark doc)
  45.     (princ)
  46.   ) ;end error
  47.   (defun Extents (plist)
  48.     (list
  49.       (apply 'mapcar (cons 'min plist))
  50.       (apply 'mapcar (cons 'max plist))
  51.     )
  52.   ) ;end
  53.   (defun CC:ZoomToPointList (pts)
  54.     (setq pts (Extents pts))
  55.     (vlax-invoke *acad* 'ZoomWindow (car pts) (cadr pts))
  56.     (vlax-invoke *acad* 'ZoomScaled 0.85 acZoomScaledRelative)
  57.   ) ;end
  58.   (defun CC:UnlockLayers (doc / laylst)
  59.     (vlax-for x (vla-get-Layers doc)
  60.       (if
  61.         (and
  62.           (not (vl-string-search "|" (vlax-get x 'Name)))
  63.           (eq :vlax-true (vla-get-lock x))
  64.         )
  65.         (progn
  66.           (setq laylst (cons x laylst))
  67.           (vla-put-lock x :vlax-false)
  68.         )
  69.       )
  70.     )
  71.     laylst
  72.   ) ;end
  73.   (defun CC:RelockLayers (lst)
  74.     (foreach x lst
  75.       (vl-catch-all-apply 'vla-put-lock (list x :vlax-true))
  76.     )
  77.   ) ;end
  78.   (defun CC:GetScreenCoords ( / ViwCen ViwDim ViwSiz VptMin VptMax)
  79.     (setq ViwSiz (/ (getvar "VIEWSIZE") 2.0)
  80.       ViwCen (getvar "VIEWCTR")
  81.       ViwDim (list
  82.                (* ViwSiz (apply '/ (getvar "SCREENSIZE")))
  83.                ViwSiz
  84.              )
  85.       VptMin (mapcar '- ViwCen ViwDim)
  86.       VptMax (mapcar '+ ViwCen ViwDim)
  87.     )
  88.     (list VptMin VptMax)
  89.   ) ;end
  90.   (defun CC:Inside (p ptlist / p2 i n #)
  91.     (setq p2 (polar p 0.0 (distance (mapcar '+ (getvar "extmin") '(0 0))
  92.                             (mapcar '+ (getvar "extmax") '(0 0))
  93.                           )))
  94.     (if (not (equal (car ptlist) (last ptlist) 1e-10))
  95.       (setq ptlist (append ptlist (list (car ptlist))))
  96.     )
  97.     (setq i 0 # 0 n (1- (length ptlist)))
  98.     (while (< i n)
  99.       (if (inters p p2 (nth i ptlist)(nth (1+ i) ptlist))
  100.         (setq # (1+ #))
  101.       )
  102.       (setq i (1+ i))
  103.     )
  104.     (not (zerop (rem # 2)))
  105.   ) ; end CC:Inside
  106.   (defun CC:SSVLAList (ss / obj lst i)
  107.     (setq i 0)
  108.     (if ss
  109.       (repeat (sslength ss)
  110.         (setq obj (vlax-ename->vla-object (ssname ss i))
  111.           lst (cons obj lst)
  112.           i (1+ i)
  113.         )
  114.       )
  115.     )
  116.     (reverse lst)
  117.   ) ;end
  118.   (defun CC:AfterEnt (ent / lst entlst)
  119.     (while (setq ent (entnext ent))
  120.       (setq entlst (entget ent))
  121.       (if
  122.         (and
  123.           (not (wcmatch (cdr (assoc 0 entlst)) "ATTRIB,VERTEX,SEQEND"))
  124.           (eq (cdr (assoc 410 entlst)) (getvar "ctab"))
  125.         )
  126.         (setq lst (cons ent lst))
  127.       )
  128.     )
  129.     (reverse lst)
  130.   ) ;end
  131.   (defun CC:SpinBar (sbar)
  132.     (cond ((= sbar "\") "|")
  133.       ((= sbar "|") "/")
  134.       ((= sbar "/") "-")
  135.       (t "\")
  136.     )
  137.   ) ;end
  138.   (defun CC:TraceObject (obj / typlst typ ZZeroList TracePline
  139.                           TraceCE TraceSpline)
  140.     (defun ZZeroList (lst)
  141.       (mapcar '(lambda (p) (list (car p) (cadr p) 0.0)) lst)
  142.     )
  143.     (defun TracePline (obj / param endparam anginc tparam pt blg
  144.                         ptlst delta inc arcparam flag)
  145.       (setq param (vlax-curve-getStartParam obj)
  146.         endparam (vlax-curve-getEndParam obj)
  147.         anginc (* pi (/ 2.5 180.0))
  148.       )
  149.       (while (<= param endparam)
  150.         (setq pt (vlax-curve-getPointAtParam obj param))
  151.         (if (not (equal pt (car ptlst) 1e-12))
  152.           (setq ptlst (cons pt ptlst))
  153.         )
  154.         (if
  155.           (and
  156.             (/= param endparam)
  157.             (setq blg (abs (vlax-invoke obj 'GetBulge param)))
  158.             (/= 0 blg)
  159.           )
  160.           (progn
  161.             (setq delta (* 4 (atan blg))
  162.               inc (/ 1.0 (1+ (fix (/ delta anginc))))
  163.               arcparam (+ param inc)
  164.             )
  165.             (while (< arcparam (1+ param))
  166.               (setq pt (vlax-curve-getPointAtParam obj arcparam)
  167.                 ptlst (cons pt ptlst)
  168.                 arcparam (+ inc arcparam)
  169.               )
  170.             )
  171.           )
  172.         )
  173.         (setq param (1+ param))
  174.       ) ;while
  175.       (if (> (length ptlst) 1)
  176.         (progn
  177.           (setq ptlst (vl-remove nil ptlst))
  178.           (ZZeroList (reverse ptlst))
  179.         )
  180.       )
  181.     ) ;end
  182.     (defun TraceCE (obj / startparam endparam anginc
  183.                      delta div inc pt ptlst)
  184.       (setq startparam (vlax-curve-getStartParam obj)
  185.         endparam (vlax-curve-getEndParam obj)
  186.         anginc (* pi (/ 2.5 180.0))   
  187.       )
  188.       (if (equal endparam (* pi 2) 1e-6)
  189.         (setq delta endparam)
  190.         (setq delta (abs (- endparam startparam)))
  191.       )
  192.       (setq div (1+ (fix (/ delta anginc)))
  193.         inc (/ delta div)
  194.       )
  195.       (while
  196.         (or
  197.           (< startparam endparam)
  198.           (equal startparam endparam 1e-12)
  199.         )
  200.         (setq pt (vlax-curve-getPointAtParam obj startparam)
  201.           ptlst (cons pt ptlst)
  202.           startparam (+ inc startparam)
  203.         )
  204.       )
  205.       (ZZeroList (reverse ptlst))
  206.     ) ;end
  207.     (defun TraceSpline (obj / startparam endparam ncpts inc param
  208.                          fd ptlst pt1 pt2 ang1 ang2 a)
  209.       (setq startparam (vlax-curve-getStartParam obj)
  210.         endparam (vlax-curve-getEndParam obj)
  211.         ncpts (vlax-get obj 'NumberOfControlPoints)
  212.         inc (/ (- endparam startparam) (* ncpts 6))
  213.         param (+ inc startparam)
  214.         fd (vlax-curve-getfirstderiv obj param)
  215.         ptlst (cons (vlax-curve-getStartPoint obj) ptlst)
  216.       )
  217.       (while (< param endparam)
  218.         (setq pt1 (vlax-curve-getPointAtParam obj param)
  219.           ang1 (angle pt1 (mapcar '+ pt1 fd))
  220.           param (+ param inc)
  221.           pt2 (vlax-curve-getPointAtParam obj param)
  222.           fd (vlax-curve-getfirstderiv obj param)
  223.           ang2 (angle pt2 (mapcar '+ pt2 fd))
  224.           a (abs (@delta ang1 ang2))
  225.         )
  226.         (if (> a 0.00436332)
  227.           (setq ptlst (cons pt1 ptlst))
  228.         )
  229.       )
  230.       (if
  231.         (not
  232.           (equal
  233.             (setq pt1 (vlax-curve-getEndPoint obj)) (car ptlst) 1e-8))
  234.         (setq ptlst (cons pt1 ptlst))
  235.       )
  236.       (ZZeroList (reverse ptlst))
  237.     ) ;end
  238.     (setq typlst '("AcDb2dPolyline" "AcDbPolyline" "AcDbSpline"
  239.                     "AcDbCircle" "AcDbEllipse")
  240.     )
  241.     (or
  242.       (eq (type obj) 'VLA-OBJECT)
  243.       (setq obj (vlax-ename->vla-object obj))
  244.     )
  245.     (setq typ (vlax-get obj 'ObjectName))
  246.     (if (vl-position typ typlst)
  247.       (cond
  248.         ((or (eq typ "AcDb2dPolyline") (eq typ "AcDbPolyline"))
  249.           (cond
  250.             ((or
  251.                (not (vlax-property-available-p obj 'Type))
  252.                (= 0 (vlax-get obj 'Type))
  253.              )
  254.               (TracePline obj)
  255.             )
  256.           )
  257.         )
  258.         ((or (eq typ "AcDbCircle") (eq typ "AcDbEllipse"))
  259.           (TraceCE obj)
  260.         )
  261.         ((eq typ "AcDbSpline")
  262.           (TraceSpline obj)
  263.         )
  264.       )
  265.     )
  266.   ) ;end CC:TraceObject
  267.   (defun CC:GetInters (firstobj nextobj mode / coord ptlst)
  268.     (if (= (type firstobj) 'ENAME)
  269.       (setq firstobj (vlax-ename->vla-object firstobj)))
  270.     (if (= (type nextobj) 'ENAME)
  271.       (setq nextobj (vlax-ename->vla-object nextobj)))
  272.     (if
  273.       (not
  274.         (vl-catch-all-error-p
  275.           (setq coord (vl-catch-all-apply 'vlax-invoke
  276.                         (list firstobj 'IntersectWith nextobj mode)))
  277.         )
  278.       )
  279.       (repeat (/ (length coord) 3)
  280.         (setq ptlst (cons (list (car coord) (cadr coord) (caddr coord)) ptlst))
  281.         (setq coord (cdddr coord))
  282.       )
  283.     )
  284.     (reverse ptlst)
  285.   ) ;end
  286.   (defun CC:CommandExplode (obj / lay mark attlst name exlst newattlst)
  287.     (setq mark (entlast))
  288.     (if
  289.       (and
  290.         (not (vlax-erased-p obj))
  291.         (eq "AcDbBlockReference" (vlax-get obj 'ObjectName))
  292.       )
  293.       (progn
  294.         (setq lay (vlax-get obj 'Layer)
  295.           attlst (vlax-invoke obj 'GetAttributes)
  296.         )
  297.         (vl-cmdf "._explode" (vlax-vla-object->ename obj))
  298.         (command)
  299.         (if
  300.           (and
  301.             (not (eq mark (entlast)))
  302.             (setq exlst (CC:SSVLAList (ssget "_p")))
  303.           )
  304.           (progn
  305.             (setq newattlst (CC:AttributesToText attlst))
  306.             (foreach x exlst
  307.               (if (eq "AcDbAttributeDefinition" (vlax-get x 'ObjectName))
  308.                 (vla-delete x)
  309.               )
  310.             )
  311.             (setq exlst (vl-remove-if 'vlax-erased-p exlst))
  312.             (if newattlst (setq exlst (append exlst newattlst)))
  313.             (foreach x exlst
  314.               (if (eq "0" (vlax-get x 'Layer))
  315.                 (vlax-put x 'Layer lay)
  316.               )
  317.               (if (zerop (vlax-get x 'Color))
  318.                 (vlax-put x 'Color 256)
  319.               )
  320.             )
  321.           )
  322.         )
  323.       )
  324.     ) ;if
  325.     (foreach x exlst
  326.       (if
  327.         (and
  328.           (not (vlax-erased-p x))
  329.           (eq "AcDbBlockReference" (vlax-get x 'ObjectName))
  330.         )
  331.         (CC:ExpNestedBlock x)
  332.       )
  333.     )
  334.   ) ;end CC:CommandExplode
  335.   (defun CC:ExpNestedBlock (obj / lay lst attlst)
  336.     (princ
  337.       (strcat "\rProcessing blocks... "
  338.         (setq *sbar (CC:SpinBar *sbar)) "\t")
  339.     )
  340.     (if
  341.       (and
  342.         obj
  343.         (not (vlax-erased-p obj))
  344.       )
  345.       (cond
  346.         ((not (CC:UniformScale obj))
  347.           (CC:CommandExplode obj)
  348.         )   
  349.         (T
  350.           (setq lay (vlax-get obj 'Layer))
  351.           (if (eq "AcDbBlockReference" (vlax-get obj 'ObjectName))
  352.             (setq attlst (CC:AttributesToText (vlax-invoke obj 'GetAttributes)))
  353.           )
  354.           (setq lst (vl-catch-all-apply 'vlax-invoke (list obj 'Explode)))
  355.           (if attlst (setq lst (append lst attlst)))
  356.           (if (listp lst)
  357.             (foreach x lst
  358.               (vla-update x) ;testing
  359.               (if (eq "AcDbBlockReference" (vlax-get x 'ObjectName))
  360.                 (CC:ExpNestedBlock x)
  361.                 (progn
  362.                   (if
  363.                     (and
  364.                       (not (vlax-erased-p x))
  365.                       (eq "0" (vlax-get x 'Layer))
  366.                     )
  367.                     (vlax-put x 'Layer lay)
  368.                   )
  369.                   (if
  370.                     (and
  371.                       (not (vlax-erased-p x))
  372.                       (zerop (vlax-get x 'Color))
  373.                     )
  374.                     (vlax-put x 'Color 256)
  375.                   )
  376.                   (if
  377.                     (and
  378.                       (not (vlax-erased-p x))
  379.                       (eq "AcDbAttributeDefinition" (vlax-get x 'ObjectName))
  380.                     )
  381.                     (vla-delete x)
  382.                   )
  383.                 )
  384.               )
  385.             )
  386.           )
  387.           (vla-delete obj)
  388.         )
  389.       ) ;cond
  390.     ) ;if
  391.   ) ;end
  392.   (defun CC:FirstLastPts (obj / p1 p2)
  393.     (setq p1 (vlax-curve-getPointAtParam obj (vlax-curve-getStartParam obj)))
  394.     (setq p2 (vlax-curve-getPointAtParam obj (vlax-curve-getEndParam obj)))
  395.     (equal p1 p2 1e-10)
  396.   )
  397.   (defun CC:GetBlock ()
  398.     (vlax-get (vla-get-ActiveLayout doc) 'Block)
  399.   ) ;end
  400.   (defun CC:AttributesToText (attlst / elst res)
  401.     (foreach x attlst
  402.       (setq elst (entget (vlax-vla-object->ename x)))
  403.       (if
  404.         (entmake
  405.           (list
  406.             '(0 . "TEXT")
  407.             (cons 1 (vlax-get x 'TextString))
  408.             (cons 7 (vlax-get x 'StyleName))
  409.             (cons 8 (vlax-get x 'Layer))
  410.             (cons 10 (vlax-get x 'InsertionPoint))
  411.             (cons 11 (vlax-get x 'TextAlignmentPoint))
  412.             (cons 40 (vlax-get x 'Height))
  413.             (cons 41 (vlax-get x 'ScaleFactor))
  414.             (cons 50 (vlax-get x 'Rotation))
  415.             (cons 51 (vlax-get x 'ObliqueAngle))
  416.             (cons 62 (vlax-get x 'Color))
  417.             (cons 67 (cdr (assoc 67 elst)))
  418.             (cons 71 (cdr (assoc 71 elst)))
  419.             (cons 72 (cdr (assoc 72 elst)))
  420.             (cons 73 (cdr (assoc 73 elst)))
  421.             (cons 410 (cdr (assoc 410 elst)))
  422.           )
  423.         ) ;make
  424.         (setq res (cons (vlax-ename->vla-object (entlast)) res))
  425.       )
  426.     )
  427.     res
  428.   ) ;end
  429.   (defun CC:UniformScale (obj / x y z)
  430.     (and
  431.       (or
  432.         (= (type obj) 'VLA-object)
  433.         (if (= (type obj) 'ENAME)
  434.           (setq obj (vlax-ename->vla-object obj))
  435.         )
  436.       )
  437.       (or
  438.         (wcmatch (vlax-get obj 'ObjectName) "*Dimension")
  439.         (and
  440.           (= "AcDbBlockReference" (vlax-get obj 'ObjectName))
  441.           (setq x (vlax-get obj 'XScaleFactor))
  442.           (setq y (vlax-get obj 'YScaleFactor))
  443.           (setq z (vlax-get obj 'ZScaleFactor))
  444.           (and
  445.             (equal (abs x) (abs y) 1e-8)
  446.             (equal (abs y) (abs z) 1e-8)
  447.           )
  448.         )
  449.       )
  450.     )
  451.   ) ;end
  452.   (defun SortInterPoints (obj pts / lst)
  453.     (if
  454.       (vl-catch-all-error-p
  455.         (vl-catch-all-apply 'vlax-curve-getEndParam (list obj))
  456.       )
  457.       pts
  458.       (progn
  459.         (setq lst (mapcar '(lambda (y) (vlax-curve-getParamAtPoint obj y)) pts)
  460.           lst (mapcar '(lambda (y z) (list y z)) lst pts)
  461.           lst (vl-sort lst '(lambda (a b) (< (car a) (car b))))
  462.         )
  463.         (mapcar 'cadr lst)
  464.       )
  465.     )
  466.   ) ;end
  467.   (vl-load-com)
  468.   (setq *acad* (vlax-get-acad-object)
  469.     doc (vla-get-ActiveDocument *acad*)
  470.   )
  471.   (vla-StartUndoMark doc)
  472.   (setq locked (CC:UnlockLayers doc))
  473.   (setq ps (getvar "pickstyle"))
  474.   (setvar "pickstyle" 0)
  475.   (setvar "cmdecho" 0)
  476.   (setq elev (getvar "elevation"))
  477.   (setvar "elevation" 0.0)
  478.   (setq osm (getvar "osmode"))
  479.   (setvar "osmode" 0)
  480.   (setq as (getvar "autosnap"))
  481.   (setvar "autosnap" 0)
  482.   (setq om (getvar "orthomode"))
  483.   (setvar "orthomode" 0)
  484.   (setq emode (getvar "edgemode"))
  485.   (setvar "edgemode" 0)
  486.   (setq pmode (getvar "projmode"))
  487.   (setvar "projmode" 0)
  488.   (setq offd (getvar "offsetdist"))
  489.   (sssetfirst)
  490.   (setq typlst '("AcDbCircle" "AcDbPolyline" "AcDb2dPolyline"
  491.                   "AcDbEllipse" "AcDbSpline"))
  492.   (setvar "errno" 0)
  493.   (while
  494.     (or
  495.       (not (setq e (car (entsel
  496.                           "\nSelect circle or closed polyline, ellipse or spline for trimming edge: "))))
  497.       (not (setq trimobj (vlax-ename->vla-object e)))
  498.       (not (vl-position (setq typ (vlax-get trimobj 'ObjectName)) typlst))
  499.       (and
  500.         (not (CC:FirstLastPts trimobj))
  501.         (setq notclosed T)
  502.       )
  503.       (and
  504.         (wcmatch typ "*Polyline")
  505.         (vlax-property-available-p trimobj 'Type)
  506.         (not (zerop (vlax-get trimobj 'Type)))
  507.         (setq splinetyp T)
  508.       )
  509.       (and
  510.         (wcmatch typ "*Polyline,AcDbSpline")
  511.         (vl-catch-all-error-p
  512.           (setq reg
  513.             (vl-catch-all-apply 'vlax-invoke
  514.               (list (CC:GetBlock) 'AddRegion (list trimobj))
  515.             )
  516.           )
  517.         )
  518.         (setq selfinter T)
  519.       )
  520.     )
  521.     (cond
  522.       ((= 52 (getvar "errno"))
  523.         (exit)
  524.       )
  525.       ((not e)
  526.         (princ "\n Missed pick. ")
  527.       )
  528.       (selfinter
  529.         (princ "\n Selected object intersects itself, try again. ")
  530.         (setq selfinter nil)
  531.       )
  532.       (notclosed
  533.         (princ "\n Selected object is not closed, try again. ")
  534.         (setq notclosed nil)
  535.       )
  536.       (splinetyp
  537.         (princ "\n Polyline spline selected, try again. ")
  538.         (setq splinetyp nil)
  539.       )
  540.       (typ
  541.         (princ (strcat "\n " (substr typ 5) " selected, try again. "))
  542.         (setq typ nil)
  543.       )
  544.     )
  545.   )
  546.   (if
  547.     (and
  548.       reg
  549.       (not (vl-catch-all-error-p reg))
  550.     )
  551.     (vla-delete (car reg))
  552.   )
  553.   (setq trimename (vlax-vla-object->ename trimobj))
  554.   (setq curcoord (CC:GetScreenCoords))
  555.   (vla-highlight trimobj acTrue)
  556.   (initget 1)
  557.   (setq UCSpkpt (getpoint "\nPick point on side to trim: "))
  558.   (setq WCStrimobjpts (CC:TraceObject trimobj))
  559.   (setq UCStrimobjpts
  560.     (mapcar '(lambda (x) (trans x 0 1)) WCStrimobjpts)
  561.   )
  562.   (if (CC:Inside UCSpkpt UCStrimobjpts)
  563.     (setq side "inside")
  564.     (setq side "outside")
  565.   )
  566.   (setq ext (Extents WCStrimobjpts))
  567.   (setq d (distance (car ext) (cadr ext)))
  568.   (setq d (/ d 1500.0))
  569.   (if (= 2 (getvar "lunits"))
  570.     (setq d (/ d 12.0))
  571.   )
  572.   (setq mark (entlast))
  573.   (vl-cmdf "._offset" d (vlax-vla-object->ename trimobj) UCSpkpt "_exit")
  574.   (setq offsetename (entlast))
  575.   (if (/= 1 (length (setq dellst (CC:AfterEnt mark))))
  576.     (progn
  577.       (princ "\nProblem detected with selected object. Try another. Exiting... ")
  578.       (foreach x dellst (entdel x))
  579.       (exit)
  580.     )
  581.   )
  582.   (setq offsetobj (vlax-ename->vla-object offsetename))
  583.   (vlax-put offsetobj 'Visible 0)
  584.   (setq hidelst (cons offsetobj hidelst))
  585.   (initget "Yes No")
  586.   (setq delother (getkword (strcat "\nErase all objects " side "? [Yes/No] <N>: ")))
  587.   (if (not delother) (setq delother "No"))
  588.   (vlax-invoke *acad* 'ZoomExtents)
  589.   (setq sc (CC:GetScreenCoords))
  590.   (setq minpt (car sc))
  591.   (setq maxpt (cadr sc))
  592.   (vlax-put trimobj 'Visible 0)
  593.   (setq hidelst (cons trimobj hidelst))
  594.   (setq sscross (ssget "cp" UCStrimobjpts '((0 . "INSERT"))))
  595.   (if (not (setq ssinside (ssget "wp" UCStrimobjpts '((0 . "INSERT")))))
  596.     (setq ssinside (ssadd))
  597.   )
  598.   (setq i 0)
  599.   (if sscross
  600.     (repeat (sslength sscross)
  601.       (setq e (ssname sscross i))
  602.       (if
  603.         (and
  604.           (not (ssmemb e ssinside))
  605.           (setq o (vlax-ename->vla-object e))
  606.           (not (vlax-erased-p o))
  607.           (vlax-property-available-p o 'Path)
  608.         )
  609.         (progn
  610.           (CC:CommandExplode o)
  611.           (if (not (vlax-erased-p o))
  612.             (progn
  613.               (vlax-put o 'Visible 0)
  614.               (setq hidelst (cons o hidelst))
  615.             )
  616.           )
  617.         )
  618.         ;else
  619.         (CC:ExpNestedBlock o)
  620.       )
  621.       (setq i (1+ i))
  622.     )
  623.   )
  624.   (setq i 0 sscross nil ssinside nil)
  625.   (setq sscross (ssget "cp" UCStrimobjpts '((0 . "HATCH"))))
  626.   (if (not (setq ssinside (ssget "wp" UCStrimobjpts '((0 . "HATCH")))))
  627.     (setq ssinside (ssadd))
  628.   )
  629.   (if sscross
  630.     (repeat (sslength sscross)
  631.       (setq e (ssname sscross i))
  632.       (if
  633.         (and
  634.           (not (ssmemb e ssinside))
  635.           (setq o (vlax-ename->vla-object e))
  636.           (eq "AcDbHatch" (vlax-get o 'ObjectName))
  637.           (eq "SOLID" (vlax-get o 'PatternName))
  638.         )
  639.         (setq solidflag T
  640.           solidlst (cons e solidlst)
  641.         )
  642.       )
  643.       (setq i (1+ i))
  644.     )
  645.   ) ;if
  646.   (if solidflag
  647.     (progn
  648.       (initget "Yes No")
  649.       (setq solidans (getkword "\nConvert solid hatch to lines? [Yes/No] <N>: "))
  650.       (if (eq "Yes" solidans)
  651.         (foreach x solidlst
  652.           (command "._-hatchedit" x
  653.             "_properties" "ANSI31" (* d 8) 0.0)
  654.           (vlax-put (vlax-ename->vla-object x) 'AssociativeHatch 0)
  655.           (command "._explode" x)
  656.         )
  657.       )
  658.     )
  659.   )
  660.   (setq i 0 sscross nil ssinside nil)
  661.   (setq sscross (ssget "cp" UCStrimobjpts '((0 . "HATCH,REGION"))))
  662.   (if (not (setq ssinside (ssget "wp" UCStrimobjpts '((0 . "HATCH,REGION")))))
  663.     (setq ssinside (ssadd))
  664.   )
  665.   (if sscross
  666.     (repeat (sslength sscross)
  667.       (setq e (ssname sscross i))
  668.       (if
  669.         (and
  670.           (not (ssmemb e ssinside))
  671.           (not (vl-position e solidlst))
  672.         )
  673.         (progn
  674.           (setq o (vlax-ename->vla-object e))
  675.           (if (vlax-property-available-p o 'AssociativeHatch)
  676.             (vlax-put o 'AssociativeHatch 0)
  677.           )
  678.           (command "._explode" e)
  679.         )
  680.       )
  681.       (setq i (1+ i))
  682.     )
  683.   )
  684.   (setq sscross nil ssinside nil)
  685.   (setq ssall (ssget "c" minpt maxpt))
  686.   (if (not (setq ssinside (ssget "wp" UCStrimobjpts)))
  687.     (setq ssinside (ssadd))
  688.   )
  689.   (if (not (setq sscross (ssget "cp" UCStrimobjpts))) ;var added
  690.     (setq sscross (ssadd))
  691.   )
  692.   (setq i 0)
  693.   (setq ssoutside (ssadd))
  694.   (repeat (sslength ssall)
  695.     (setq e (ssname ssall i))
  696.     (if (not (ssmemb e sscross))
  697.       (ssadd e ssoutside)
  698.     )
  699.     (setq i (1+ i))
  700.   )
  701.   (setq i 0)
  702.   (setq ssintersect (ssadd))
  703.   (repeat (sslength sscross)
  704.     (setq e (ssname sscross i))
  705.     (if
  706.       (and
  707.         (not (ssmemb e ssinside))
  708.         (not (vl-position e solidlst))
  709.         (CC:GetInters e trimobj acExtendNone)
  710.       )
  711.       (ssadd e ssintersect)
  712.       (ssadd e ssinside)
  713.     )
  714.     (setq i (1+ i))
  715.   )
  716.   (if (eq "Yes" delother)
  717.     (cond
  718.       ((eq side "inside")
  719.         (ssdel trimename ssinside) ;check
  720.         (command "._erase" ssinside "")
  721.       )
  722.       ((eq side "outside")
  723.         (ssdel trimename ssoutside) ;check
  724.         (command "._erase" ssoutside "")
  725.       )
  726.     )
  727.   )
  728.   (setq lst (CC:SSVLAList ssintersect))
  729.   (setq lst
  730.     (vl-remove-if
  731.       '(lambda (x)
  732.          (setq typ (vlax-get x 'ObjectName))
  733.          (or
  734.            (eq "AcDbText" typ)
  735.            (eq "AcDbMText" typ)
  736.            (eq "AcDbLeader" typ)
  737.            (wcmatch typ "*Dimension")
  738.            (eq "AcDbHatch" typ)  
  739.            (eq "AcDbSolid" typ)
  740.            (eq "AcDbTrace" typ)
  741.            (eq "AcDbMLeader" typ)
  742.            (eq trimobj x)
  743.          )
  744.        )
  745.       lst
  746.     )
  747.   )
  748.   (CC:ZoomToPointList WCStrimobjpts)
  749.   (foreach x lst
  750.     (if (not (vlax-erased-p x))
  751.       (progn
  752.         (setq typ (vlax-get x 'ObjectName))
  753.         (cond
  754.           ((and
  755.              (eq "AcDbPolyline" typ)
  756.              (= -1 (vlax-get x 'Closed))
  757.            )
  758.             (vlax-put x 'Closed 0)
  759.             (setq coord (vlax-get x 'Coordinates))
  760.             (vlax-put x 'Coordinates
  761.               (append coord (list (car coord) (cadr coord)))
  762.             )
  763.             (vla-update x)
  764.           )
  765.           ((and
  766.              (eq "AcDb2dPolyline" typ)
  767.              (= -1 (vlax-get x 'Closed))
  768.            )
  769.             (vlax-put x 'Closed 0)
  770.             (setq coord (vlax-get x 'Coordinates))
  771.             (vlax-put x 'Coordinates
  772.               (append coord (list (car coord) (cadr coord) (caddr coord)))
  773.             )
  774.             (vla-update x)
  775.           )
  776.         )
  777.       )
  778.     )
  779.     (if (setq intpts (CC:GetInters offsetobj x acExtendNone))
  780.       (progn
  781.         (if (> (length intpts) 2)
  782.           (setq intpts (SortInterPoints x intpts))
  783.         )
  784.         (foreach p intpts
  785.           (setq mark (entlast))
  786.           (if
  787.             (and
  788.               (not (vl-catch-all-error-p
  789.                      (vl-catch-all-apply 'vlax-curve-getParamAtPoint (list x p)))
  790.               )
  791.               (vlax-curve-getParamAtPoint x p)
  792.             )
  793.             (vl-cmdf "._trim" trimename ""
  794.               (list (vlax-vla-object->ename x) (trans p 0 1)) "")
  795.           )
  796.           (if (not (eq mark (entlast)))
  797.             (setq postlst (cons (entlast) postlst))
  798.           )
  799.         )
  800.       )
  801.     )
  802.   )
  803.   (while postlst
  804.     (setq intpts nil)
  805.     (foreach x postlst
  806.       (if (setq intpts (CC:GetInters offsetobj x acExtendNone))
  807.         (progn
  808.           (if (> (length intpts) 2)
  809.             (setq intpts (SortInterPoints x intpts))
  810.           )
  811.           (foreach p intpts
  812.             (setq mark nil)
  813.             (setq mark (entlast))
  814.             (if
  815.               (and
  816.                 (not (vl-catch-all-error-p
  817.                        (vl-catch-all-apply 'vlax-curve-getParamAtPoint (list x p)))
  818.                 )
  819.                 (vlax-curve-getParamAtPoint x p)
  820.               )
  821.               (vl-cmdf "._trim" trimename "" (list x (trans p 0 1)) "")
  822.             )
  823.             (setq postlst (vl-remove x postlst))
  824.             (if (not (eq mark (entlast)))
  825.               (setq postlst (cons (entlast) postlst))
  826.             )
  827.           )
  828.           (setq postlst (vl-remove x postlst))
  829.         )
  830.         (setq postlst (vl-remove x postlst))
  831.       )
  832.     )
  833.   )
  834.   (if
  835.     (and
  836.       (eq "Yes" delother)
  837.       trimobj
  838.       offsetobj
  839.       (not (CC:GetInters offsetobj trimobj acExtendNone))
  840.     )
  841.     (cond
  842.       ((and
  843.          (eq side "inside")
  844.          (setq WCSoffsetobjpts (CC:TraceObject offsetobj))
  845.          (setq UCSoffsetobjpts
  846.            (mapcar '(lambda (x) (trans x 0 1)) WCSoffsetobjpts)
  847.          )
  848.        )
  849.         (if (setq sstest (ssget "_cp" UCSoffsetobjpts))
  850.           (command "._erase" sstest "")
  851.         )
  852.       )
  853.       ((eq side "outside")
  854.         (setq mark (entlast))
  855.         ;; multiply be 2 or 3?
  856.         (vl-cmdf "._offset" (* d 3) offsetename UCSpkpt "_exit")
  857.         (if
  858.           (and
  859.             (not (eq mark (setq testename (entlast))))
  860.             (not (CC:GetInters testename trimobj acExtendNone))
  861.             (setq WCSoffsetobjpts (CC:TraceObject testename))
  862.             (setq UCSoffsetobjpts
  863.               (mapcar '(lambda (x) (trans x 0 1)) WCSoffsetobjpts)
  864.             )
  865.           )
  866.           (progn
  867.             (setq sskeep (ssget "_wp" UCSoffsetobjpts))
  868.             (vlax-invoke *acad* 'ZoomExtents)
  869.             (setq sc (CC:GetScreenCoords)
  870.               minpt (car sc)
  871.               maxpt (cadr sc)
  872.               sstest (ssget "_c" minpt maxpt)
  873.               i 0
  874.             )
  875.             (if
  876.               (and
  877.                 sskeep
  878.                 sstest
  879.                 (> (sslength sstest) (sslength sskeep))
  880.               )
  881.               (repeat (sslength sstest)
  882.                 (setq e (ssname sstest i))
  883.                 (if (not (ssmemb e sskeep))
  884.                   (entdel e)
  885.                 )
  886.                 (setq i (1+ i))
  887.               )
  888.             )
  889.           )
  890.         )
  891.       )
  892.     ) ;cond
  893.   ) ;if
  894.   (command "._zoom" "_window" (car curcoord) (cadr curcoord))
  895.   (*error* nil)
  896. ) ;end


附件: 您需要 登录 才可以下载或查看,没有账号?注册
发表于 2020-7-15 11:16 | 显示全部楼层
这个是干什么的
回复

使用道具 举报

 楼主| 发表于 2020-7-15 11:58 | 显示全部楼层

裁地形图裁地形图
回复

使用道具 举报

发表于 2020-7-17 15:29 | 显示全部楼层
cass不就可以局部存盘吗
回复

使用道具 举报

发表于 2020-8-2 14:45 | 显示全部楼层
回复

使用道具 举报

发表于 2020-8-18 01:33 | 显示全部楼层
谢谢楼主分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-28 07:58 , Processed in 0.307396 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表