Author Topic: How can I catch a bad entity during an offset command?  (Read 5072 times)

0 Members and 1 Guest are viewing this topic.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How can I catch a bad entity during an offset command?
« Reply #15 on: December 07, 2009, 03:11:32 PM »
Here's one I put together a while back:

Code: [Select]
;;; Offset selected object
;;; #Ent&Point - List of entity and point
;;; #Dist - Distance to offset object
;;; #Point - Point on side of object to offset
;;; Alan J. Thompson, 09.12.09
(defun AT:Offset (#Ent&Point #Dist #Point / #POC1 #POC2 #Obj #Dist #Check)
  ;; get first point on curve
  (setq #POC1 (vlax-curve-getClosestPointTo
                (setq #Obj (vlax-ename->vla-object (car #Ent&Point)))
                (trans (cadr #Ent&Point) 1 0)
              ) ;_ vlax-curve-getClosestPointTo
  ) ;_ setq
  ;; get another point on curve, 0.0001 away
  (setq #POC2 (vlax-curve-getPointAtDist
                #Obj
                (+ (vlax-curve-getDistAtPoint #Obj #POC1) 0.0001)
              ) ;_ vlax-curve-getPointAtDist
  ) ;_ setq
  ;; determine which side #Point is on and set distance for offset
  (if (minusp (- (* (- (car #POC2) (car #POC1))
                    (- (cadr (trans #Point 1 0)) (cadr #POC1))
                 ) ;_ *
                 (* (- (cadr #POC2) (cadr #POC1))
                    (- (car (trans #Point 1 0)) (car #POC1))
                 ) ;_ *
              ) ;_ -
      ) ;_ minusp
    (if (member (vla-get-objectname #Obj) '("AcDbLine" "AcDbXline"))
      (setq #Dist (- (abs #Dist)))
      (setq #Dist (abs #Dist))
    ) ;_ if
    (if (member (vla-get-objectname #Obj) '("AcDbLine" "AcDbXline"))
      (setq #Dist (abs #Dist))
      (setq #Dist (- (abs #Dist)))
    ) ;_ if
  ) ;_ if
  ;; offset object
  (if (not (vl-catch-all-error-p
             (setq #Check (vl-catch-all-apply
                            'vla-offset
                            (list #Obj #Dist)
                          ) ;_ vl-catch-all-apply
             ) ;_ vl-catch-all-error-p
           ) ;_ vl-catch-all-error-p
      ) ;_ not
    (car (vlax-safearray->list (vlax-variant-value #Check)))
  ) ;_ if
) ;_ defun
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox