Author Topic: pls can you fix offset routine  (Read 1784 times)

0 Members and 1 Guest are viewing this topic.

dussla

  • Bull Frog
  • Posts: 297
pls can you fix offset routine
« on: March 26, 2008, 07:15:04 AM »
dear freinds
i am poor programmer.
so i use other friends  lisp   for private use , pls  forgive me.~

this attached lisp  is  modified lisp from many friends .~
pls  ,forgive me ~

this lisp is to make road line .
but there is error.

can you modify  this lisp ?

dussla

  • Bull Frog
  • Posts: 297
Re: pls can you fix offset routine
« Reply #1 on: March 26, 2008, 07:24:41 AM »
that file is my wanting result  :-) :-) :-) :-) :-)

ELOQUINTET

  • Guest
Re: pls can you fix offset routine
« Reply #2 on: March 26, 2008, 12:53:12 PM »
no need to apologize we are a friendly bunch here

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: pls can you fix offset routine
« Reply #3 on: March 26, 2008, 02:37:48 PM »
this should get things started. you had too many "" after your layer make and layer sets...

Code: [Select]
; =============================================================================
; Filename    :   MultiOffset.lsp
; Datum       :   21.11.00
; Author      :   jme
; Copyright   :   MENZI ENGINEERING GmbH, Switzerland
; Revision  1 :   19.07.01 jme - Ellipse and Spline added
;                              - Prompt for delete original objects
; Revision  2 :   14.06.02 jme - Bug OFFSETDIST -1 fixed
; Revision  3 :   12.08.04 jme - Layer support added
; Revision  4 :   15.08.04 jme - Modified for ActiveX
; Revision  5 :   11.10.05 jme - Xline support added
; Revision  6 :   __.__.__ ___ -
; -----------------------------------------------------------------------------
; Known bugs:
; - None (exept the original AutoCAD Offset bug)
; -----------------------------------------------------------------------------
; Description:
; Offsets entities to both sides of the original entity.
; -----------------------------------------------------------------------------
; Global variables:
; Me:Del  Me:Dst  Me:Lmd
; -----------------------------------------------------------------------------
; Internal LISP-functions:
; MeAll2String MeGetLockedLayers MeList2String MeOffset
; -----------------------------------------------------------------------------
; External LISP-functions:
;
; -----------------------------------------------------------------------------
; Version notes:
; AutoCAD: Version: Language: AddIns:
; 15+ 1.05 English ...
; -----------------------------------------------------------------------------
;
; == Message on loading =======================================================
;
(princ "\nroad ")
;
; == Main =====================================================================
;
(defun C:road ( / )
(setq  la1   "road-yellow" )
(setq  la2   "road-white " )
(command "-Layer" "m" la1  "c" "yellow" la1  "")
(command "-Layer" "m" la2  "c" "white" la2  "")
   (if (not road-num) (setq road-num 1))
   (setq wgetdis1 (getint (strcat "\n degrees<" (itoa road-num ) ">:")))
   (if wgetdis1 (setq road-num wgetdis1))
 (if (< (atof (getvar "ACADVER")) 15.0)
  (alert " MultiOffset requires AutoCAD 2000 or higher. ")
  (progn
   (vl-load-com)
   
   (setq CurLay (getvar "CLAYER")
         AcaDoc (vla-get-ActiveDocument (vlax-get-acad-object))
LokLst (MeGetLockedLayers AcaDoc)
LokLst (cond (LokLst (MeList2String LokLst ",")) ("~*"))

         FltLst (list
                '(-4 . "<OR")
                 '(0 . "ARC,CIRCLE,ELLIPSE,LINE,LWPOLYLINE,SPLINE,XLINE")
                 '(-4 . "<AND")
                  '(0 . "POLYLINE")
                  '(-4 . "<NOT")
                   '(-4 . "<OR")
                    '(-4 . "&=") '(70 .  8)  ;3DPoly
                    '(-4 . "&=") '(70 . 16)  ;3DMesh
                    '(-4 . "&=") '(70 . 64)  ;PolyFace
                   '(-4 . "OR>")
                  '(-4 . "NOT>")
                 '(-4 . "AND>")
                '(-4 . "OR>")
                '(-4 . "<NOT") (cons 8 LokLst) '(-4 . "NOT>")
                )
   )
   (if (setq CurSet (cond ((ssget "I" FltLst)) ((ssget FltLst))))
    (progn
         
     (vla-StartUndoMark AcaDoc)
     (while (setq CurEnt (ssname CurSet 0))
           

(command "-Layer" "s" la1  "")

(setq  yello-dst  125 ) 
(setq CurObj (vlax-ename->vla-object CurEnt))
;(command "change" curobj "" "P"  "c" 1 "")
(vla-put-layer CurObj la1)
     (setq   FstLst (MeOffset CurObj yello-dst) )
(setq NxtLst (MeOffset CurObj (- yello-dst)) )
     
 
(setq  me:dst  3000)


(command "-Layer" "s" la2  "")
;(setq  road-num  (- road-num 1))
         (repeat road-num         
             (setq CurObj (vlax-ename->vla-object CurEnt) )
; (command "change" curobj "" "P"  "c" 2 "")
(vla-put-layer CurObj la2)
(setq    FstLst (MeOffset CurObj Me:Dst) )
; (setq    NxtLst (MeOffset CurObj (- Me:Dst)) )


(setq  me:dst  (+ me:dst 3000 )) 

)
  (setq  me:dst  nil)
  (ssdel CurEnt CurSet)
      (vla-delete CurObj)
       
     
     )
     
     (vla-EndUndoMark AcaDoc)
    )
   )
  )
 )
 (princ)
 
 (setq yellow-width (ssget "X" (list (cons 8 la1))))
 (setq white-width (ssget "X" (list (cons 8 la2))))
 (command "PEDIT" yellow-width "w" 100 "")
 (command "PEDIT" white-width "w" 100 "")
 (setq white-width2 (ssget "X" (list (cons 8 la2))))
; (command "change" yellow-width "" "P"  "c" 1 "")
 (load-line-types "ACAD_ISO03W100" "acad.lin")   
 (command "change" white-width2 "" "P"  "lt" "ACAD_ISO03W100" "")
)
;
; == Subs =====================================================================
;
; -- Function MeAll2String
; Converts all variable types to a string.
; Arguments [Type]:
;   Val = Value to convert [INT/REAL/LIST/STR]
; Return [Type]:
;   > Converted value [STR]
; Notes:
;   None
;
(defun MeAll2String (Val)
 (cond
  ((= (type Val) 'INT ) (itoa Val))
  ((= (type Val) 'REAL) (rtos Val))
  ((= (type Val) 'LIST) (MeList2String Val " "))
  ((= (type Val) 'STR ) Val)
  (T "")
 )
)
;
; -- Function MeGetLockedLayers
; Returns a list of all locked layers
; Arguments [Typ]:
;   Acd = Acad document object [VLA-OBJECT]
; Return [Typ]:
;   > Layer names [LIST]
;   > nil if none
; Notes:
;   None
;
(defun MeGetLockedLayers (Acd / NmeLst)
 (vlax-for Obj (vla-get-Layers Acd)
  (if (= (vla-get-Lock Obj) :vlax-true)
   (setq NmeLst (cons (vla-get-name Obj) NmeLst))
  )
  (vlax-release-object Obj)
 )
 (reverse NmeLst)
)
;
; -- Function MeList2String
; Converts a list to a string with selectable delimiter.
; Arguments [Typ]:
;   Lst = List [LIST]
;   Del = Delimiter [STR]
; Return [Typ]:
;   > Converted list [STR]
; Notes:
;   None
;
(defun MeList2String (Lst Del)
 (apply 'strcat
  (cons
   (MeAll2String (car Lst))
   (mapcar
   '(lambda (l) (strcat Del (MeAll2String l)))
    (cdr Lst)
   )
  )
 )
)
;
; -- Function MeOffset
; Error watched Offset methode.
; Arguments [Type]:
;   Obj = Object to offset [VLA-OBJECT]
;   Dst = Offset distance [REAL]
; Return [Type]:
;   > Offset object list [LIST]
;   > False if offset fails
; Notes:
;   None
;
(defun MeOffset (Obj Dst / TmpLst)
 (if (not
      (vl-catch-all-error-p
       (setq TmpLst (vl-catch-all-apply 'vlax-invoke (list Obj 'Offset Dst)))
      )
     )
  TmpLst
 )
)

;;;===================================================================;
;;; FIND-LINE-TYPES                                                   ;
;;;-------------------------------------------------------------------;
;;; This searches a linetype collection object and determines if      ;
;;; the linetype is present in the collection.                        ;
;;;                                                                   ;
;;; Note: l-obj is a local variable within the scope of the vlax-for  ;
;;;       function because it is used within a "for" expression       ;
;;;                                                                   ;
;;; Arguments: line-type = A string which denotes the linetype        ;
;;;                        to search for in the line-type-collection  ;
;;;                        argument.                                  ;
;;;            line-type-collection = A vla collection object which   ;
;;;                                   contains the current linetypes  ;
;;;                                   loaded in ACAD.                 ;
;;;                                                                   ;
;;; Returned Value: If the linetype is found a vla linetype object    ;
;;;                 is returned such as:                              ;
;;;                 #<VLA-OBJECT IAcadLineType 03fe0b00>              ;
;;;                 (If the linetype search fails this function       ;
;;;                  returns n(defun TxtStr (x)
;;;                                                                   ;
;;; Usage: (load-line-types "CENTER" "acad.lin")                      ;
;;;===================================================================;
(defun find-line-type (line-type line-type-collection / res)
  (setq line-type (strcase line-type))
  (vlax-for l-obj line-type-collection
    (if (= (strcase (vla-get-name l-obj)) line-type)
      (setq res l-obj)
    )
  )
  res
)
;;;===================================================================;
;;; LOAD-LINE-TYPES                                                   ;
;;;-------------------------------------------------------------------;
;;; This function loads a linetype in to the drawing                  ;
;;;                                                                   ;
;;; Required Functions: find-line-type                                ;
;;;                                                                   ;
;;; Arguments: line-type = A string which denotes the LT to load      ;
;;;            file-name = A string which denotes the LT file to      ;
;;;                        which to load the requested linetype       ;
;;;                                                                   ;
;;; Returned Value:  A vla linetype object objects such as:           ;
;;;                  #<VLA-OBJECT IAcadLineType 03fe0b00>             ;
;;;                                                                   ;
;;; Usage: (load-line-types "CENTER" "acad.lin")                      ;
;;;===================================================================;
(defun load-line-types (line-type file-name / tmp res)
  (if (and (setq tmp (vlax-get-acad-object))
           (setq tmp (vla-get-activedocument tmp))
           (setq tmp (vla-get-linetypes tmp));; linetypes is the last
                                             ;; set and the current
                                             ;; linetype collection
      )
    (if (setq res (find-line-type line-type tmp))
      res
      (progn
       ;; load the linetype
        (vla-load tmp line-type file-name)
       ;; since the vla-load function returns nil
       ;; we force the following function to test if
       ;; the load was successful. If success the
       ;; return the vla linetype object
        (if (vla-item tmp line-type)
          (vla-item tmp line-type)
          ;; Nothing was loaded so we return nil
          nil
        )   ;; _test to see if the line was loaded
      )     ;; evaluate when the linetype is not loaded in acad
    )       ;; end if for check if linetype is loaded
    nil
  )         ;; end if for various calls to ACAD
)

;
; == Copyright - Note (May be never deleted) ==================================
;
(princ "\n------------------------------------------------")
(princ "\nType road ...")
(princ)
;
; == End MultiOffset ==========================================================
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox