Jump to content

Make boundary


Jord_91

Recommended Posts

Hey guy's I've got this lisp that is working pretty well with an end user but when I try to add it to a script it saids that it's an Unknown command... is there something in it that is wrong? 

(defun lib:Zoom2Lst( vlist / bl tr Lst OS)
(setq Lst (lib:pt_extents vlist)
bl (car Lst) tr (cadr Lst))
(if (not (and (lib:IsPtInView bl) (lib:IsPtInView tr)))
(progn  (setq OS (getvar "OSMODE"))(setvar "OSMODE" 0)
(command "_.Zoom" "_Window" (trans bl 0 1)(trans tr 0 1)
 "_.Zoom" "0.95x")
(setvar "OSMODE" OS)
 T) NIL))
;External contour of objects
(defun C:MakeBoundary ( / *error* blk obj MinPt MaxPt hiden pt pl unnamed_block isRus
      tmp_blk adoc blks lays lay oname sel csp loc sc ec ret DS osm iNSpT)
(defun *error* (msg)(princ msg)(mapcar '(lambda (x) (vla-put-Visible x :vlax-true)) hiden)
(vla-endundomark adoc)(if (and tmp_blk (not (vlax-erased-p tmp_blk))(vlax-write-enabled-p tmp_blk) )
(vla-Erase tmp_blk))(if osm (setvar "OSMODE" osm))(foreach x loc (vla-put-lock x :vlax-true)))
(vl-load-com)(setvar "CMDECHO" 0)(setq osm (getvar "OSMODE"))
(if (zerop (getvar "WORLDUCS"))(progn(vl-cmdf "_.UCS" "")(vl-cmdf "_.Plan" "")))
(setq isRus (= (getvar "SysCodePage") "ANSI_1251"))
(setq adoc (vla-get-ActiveDocument (vlax-get-acad-object))
       blks (vla-get-blocks adoc) lays (vla-get-layers adoc))
 (vla-startundomark adoc)(if isRus (princ "\n???????? ??????? ??? ?????????? ???????")(princ "\nSelect objects for making a contour"))
 (vlax-for lay lays
     (if (= (vla-get-lock lay) :vlax-true)
         (progn (vla-put-lock lay :vlax-false) (setq loc (cons lay loc))))
     )
(if (setq sel (ssget))(progn
   (setq sel (ssnamex sel))
;;;    (setq iNSpT(apply 'mapcar (cons 'min 
;;;     (mapcar 'cadr (apply 'append (mapcar '(lambda(x)(vl-remove-if-not 'listp x)) sel))))))
   (setq iNSpT '(0 0 0))
   (setq sel (mapcar 'vlax-ename->vla-object(vl-remove-if 'listp (mapcar 'cadr sel))))
   (setq csp (vla-objectidtoobject adoc (vla-get-ownerid (car sel))))
  ; (setq unnamed_block (vla-add (vla-get-blocks adoc)(vlax-3d-point '(0. 0. 0.)) "*U"))
   (setq unnamed_block (vla-add (vla-get-blocks adoc)(vlax-3d-point inspt) "*U"))
   (foreach x sel
     (setq oname (strcase (vla-get-objectname x)))
     (cond ((member oname '("ACDBVIEWPORT" "ACDBATTRIBUTEDEFINITION" "ACDBMTEXT" "ACDBTEXT")) nil)
    ((= oname "ACDBBLOCKREFERENCE")
     (vla-InsertBlock unnamed_block
       (vla-get-insertionpoint x)(vla-get-name x)
       (vla-get-xscalefactor x)(vla-get-yscalefactor x)
       (vla-get-zscalefactor x)(vla-get-rotation x))
     (setq blk (cons x blk)))
    (t (setq obj (cons x obj)))));_foreach
       (setq lay  (vla-item lays (getvar "CLAYER")))
       (if (= (vla-get-lock lay) :vlax-true)(progn (vla-put-lock lay :vlax-false) (setq loc (cons lay loc))))
    (if obj (progn (vla-copyobjects (vla-get-activedocument (vlax-get-acad-object))
             (vlax-make-variant (vlax-safearray-fill
                 (vlax-make-safearray vlax-vbobject (cons 0 (1- (length obj))))
                 obj)) unnamed_block)))
   (setq obj (append obj blk))
   (if obj (progn
         ;(setq tmp_blk (vla-insertblock csp (vlax-3d-point '(0. 0. 0.))(vla-get-name unnamed_block) 1.0 1.0 1.0 0.0))
             (setq tmp_blk (vla-insertblock csp (vlax-3d-point inspt)(vla-get-name unnamed_block) 1.0 1.0 1.0 0.0))
         (vla-GetBoundingBox tmp_blk 'MinPt 'MaxPt)  ;_??????? ?????
              (setq MinPt (vlax-safearray->list MinPt) MaxPt (vlax-safearray->list MaxPt)
      DS (max (distance MinPt (list (car MinPt)(cadr MaxPt)))
       (distance MinPt (list (car MaxPt)(cadr MinPt))))
             DS (* 0.2 DS) ;1/5
      DS (max DS 10) MinPt (mapcar '- MinPt (list DS DS))
                    MaxPt (mapcar '+ MaxPt (list DS DS)))
(lib:Zoom2Lst (list MinPt MaxPt))(setq sset (ssget "_C" MinPt MaxPt))
(if sset (progn (setvar "OSMODE" 0)
     (setq hiden (mapcar 'vlax-ename->vla-object(vl-remove-if 'listp (mapcar 'cadr (ssnamex sset))))
    hiden (vl-remove tmp_blk hiden))
     (mapcar '(lambda(x)(vla-put-Visible x :vlax-false)) hiden)
     (setq pt (mapcar '+ MinPt (list (* 0.5 DS)(* 0.5 DS))))
     (vl-cmdf "_.RECTANG" (trans MinPt 0 1)(trans MaxPt 0 1))
     (setq pl (vlax-ename->vla-object(entlast)))
     (setq sc (1-(vla-get-count csp)))
     (if (VL-CATCH-ALL-ERROR-P (VL-CATCH-ALL-APPLY '(lambda ()
        (vl-cmdf "_-BOUNDARY" (trans pt 0 1) "")
             (while (> (getvar "CMDACTIVE") 0)(command "")))))
     (if isRus (princ "\n?? ??????? ????????? ??????")(princ "\nIt was not possible to construct a contour")))
     (setq ec (vla-get-count csp))
       (while (< sc ec)(setq ret (append ret (list (vla-item csp sc))) sc(1+ sc)))
     (setq ret (vl-remove pl ret))
     (mapcar '(lambda (x)(vla-Erase x)(vlax-release-object x))(list pl tmp_blk))(setq pl nil tmp_blk nil)
     (setq ret (mapcar '(lambda ( x / mipt)(vla-GetBoundingBox x 'MiPt nil)  ;_??????? ?????
                (setq MiPt (vlax-safearray->list MiPt))(list MiPt x)) ret))
     (setq ret (vl-sort ret '(lambda (e1 e2)(< (distance MinPt (car e1))(distance MinPt (car e2))))))
     (setq pl (nth 1 ret) ret (vl-remove pl ret)) (mapcar 'vla-erase (mapcar 'cadr ret))
     (mapcar '(lambda(x)(vla-put-Visible x :vlax-true)) hiden)
     (foreach x loc (vla-put-lock x :vlax-true))
     (if pl (progn (initget  "Yes No")
     (if (= (getkword (if isRus "\n??????? ???????? [Yes/No] <No> : " "\nDelete objects? [Yes/No] <No> : ")) "Yes")
        (mapcar '(lambda (x) (if (vlax-write-enabled-p x)(vla-Erase x))) obj)))
(if isRus (princ "\n?? ??????? ????????? ??????")(princ "\nIt was not possible to construct a contour")))))))
    (VL-CATCH-ALL-APPLY '(lambda ()(mapcar 'vlax-release-object
   (list unnamed_block tmp_blk csp blks lays))))));_if not
 (foreach x loc (vla-put-lock x :vlax-true))(setvar "OSMODE" osm)
 (vla-endundomark adoc)(vlax-release-object adoc)(princ))

Could you help me please!! :)

Edited by Jord_91
Link to comment
Share on other sites

23 minutes ago, rlx said:

Does your script include as the first line : (load "makeboundary.lsp") and where/when is this function loaded : (lib:pt_extents vlist)?

Hi, you have some great questions! In fact, I’m using the script writer of Lee Mac sort I can use normal commande of AutoCAD and usually call Lisp without probleme  . As I’m actually trying to learn lisp I’m a certified noob at what’s missing or els. 

Link to comment
Share on other sites

the same probably goes for the function

lib:IsPtInView

 

But its a common problem , forgetting to include your little 'helper' functions. Just include their defun's in your main defun


(defun c:MakeBoundary ( / _lib1 _lib2 var1 var2 etc.)

  (defun _lib1 ()(bladiebla))

  (defun _lib2 ()(blehdiebleh))

  (setq var1 1 var2 2)

  ; etc

  (princ)

)

Link to comment
Share on other sites

14 hours ago, rlx said:

the same probably goes for the function


lib:IsPtInView

 

But its a common problem , forgetting to include your little 'helper' functions. Just include their defun's in your main defun

 


(defun c:MakeBoundary ( / _lib1 _lib2 var1 var2 etc.)

  (defun _lib1 ()(bladiebla))

  (defun _lib2 ()(blehdiebleh))

  (setq var1 1 var2 2)

  ; etc

  (princ)

)

 

In Fact, Here's the full Code

;| ! *******************************************************************
;; !                  lib:IsPtInView
;; ! *******************************************************************
;; ! ????????? ????????? ?? ????? ? ??????? ??????
;; ! Auguments: 'pt'  - ????? ??? ??????? ? ???!!!
;; ! Return   : T ??? nil ???? 'pt' ? ??????? ?????? ??? ???
;; ! *******************************************************************|;
(defun lib:IsPtInView (pt / VCTR Y_Len SSZ X_Pix Y_Pix X_Len Lc Uc)
(setq pt (trans pt 0 1))  
(setq VCTR (getvar "VIEWCTR") Y_Len (getvar "VIEWSIZE")
  SSZ (getvar "SCREENSIZE")
  X_Pix (car SSZ) Y_Pix (cadr SSZ)
  X_Len (* (/ X_Pix Y_Pix) Y_Len)
  Lc (polar VCTR (dtr 180.0) (* 0.5 X_Len))
  Uc (polar Lc 0.0 X_Len)
  Lc (polar Lc (dtr 270.0) (* 0.5 Y_Len))
  Uc (polar Uc (dtr 90.0) (* 0.5 Y_Len)))
(if (and (> (car pt) (car Lc))(< (car pt) (car Uc))
 (> (cadr pt) (cadr Lc))(< (cadr pt) (cadr Uc)))
T nil))
(defun DTR (a)(* pi (/ a 180.0)))
;| ! ***************************************************************************
;; !           lib:pt_extents
;; ! ***************************************************************************
;; ! Function : ?????????? ??????? MIN, MAX X,Y,Z ?????? ?????
;; ! Argument : 'vlist' - ?????? ?????
;; ! Returns  : ?????? ????? (??????? ?????????)
;; ! ***************************************************************************|;
(defun  lib:pt_extents (vlist / tmp)
(setq tmp (mapcar '(lambda (x) (vl-remove-if 'null x))
(mapcar '(lambda (what) (mapcar '(lambda (x) (nth what x)) vlist))
'(0 1 2))));_setq
 
 (list (mapcar '(lambda(x)(apply 'min x)) tmp)(mapcar '(lambda(x)(apply 'max x)) tmp)));_defun
;http://www.theswamp.org/index.php?topic=15123.0
;;;(defun GetBoundingBox-3d (pt_lst)
;;;  (list (apply 'mapcar (cons 'min pt_lst))
;;; (apply 'mapcar (cons 'max pt_lst))
;;;  )
;;
; ! ***********************************************************
;; !                             lib:Zoom2Lst
;; ! **********************************************************
;; ! Function : Zoom ?????? ?????? ?????
;; ! Arguments: 'vlist' - ?????? ????? ? ???!!!!
;; ! ????????? ?????, ????? ??? ????? ???? ?????
;; ! Returns  : t - ???? ???????????? nil - ???
;; ! **********************************************************
(defun lib:Zoom2Lst( vlist / bl tr Lst OS)
(setq Lst (lib:pt_extents vlist)
bl (car Lst) tr (cadr Lst))
(if (not (and (lib:IsPtInView bl) (lib:IsPtInView tr)))
(progn  (setq OS (getvar "OSMODE"))(setvar "OSMODE" 0)
(command "_.Zoom" "_Window" (trans bl 0 1)(trans tr 0 1)
 "_.Zoom" "0.95x")
(setvar "OSMODE" OS)
 T) NIL))
;External contour of objects
(defun C:ECO ( / *error* blk obj MinPt MaxPt hiden pt pl unnamed_block isRus
      tmp_blk adoc blks lays lay oname sel csp loc sc ec ret DS osm iNSpT)
(defun *error* (msg)(princ msg)(mapcar '(lambda (x) (vla-put-Visible x :vlax-true)) hiden)
(vla-endundomark adoc)(if (and tmp_blk (not (vlax-erased-p tmp_blk))(vlax-write-enabled-p tmp_blk) )
(vla-Erase tmp_blk))(if osm (setvar "OSMODE" osm))(foreach x loc (vla-put-lock x :vlax-true)))
(vl-load-com)(setvar "CMDECHO" 0)(setq osm (getvar "OSMODE"))
(if (zerop (getvar "WORLDUCS"))(progn(vl-cmdf "_.UCS" "")(vl-cmdf "_.Plan" "")))
(setq isRus (= (getvar "SysCodePage") "ANSI_1251"))
(setq adoc (vla-get-ActiveDocument (vlax-get-acad-object))
       blks (vla-get-blocks adoc) lays (vla-get-layers adoc))
 (vla-startundomark adoc)(if isRus (princ "\n???????? ??????? ??? ?????????? ???????")(princ "\nSelect objects for making a contour"))
 (vlax-for lay lays
     (if (= (vla-get-lock lay) :vlax-true)
         (progn (vla-put-lock lay :vlax-false) (setq loc (cons lay loc))))
     )
(if (setq sel (ssget))(progn
   (setq sel (ssnamex sel))
;;;    (setq iNSpT(apply 'mapcar (cons 'min 
;;;     (mapcar 'cadr (apply 'append (mapcar '(lambda(x)(vl-remove-if-not 'listp x)) sel))))))
   (setq iNSpT '(0 0 0))
   (setq sel (mapcar 'vlax-ename->vla-object(vl-remove-if 'listp (mapcar 'cadr sel))))
   (setq csp (vla-objectidtoobject adoc (vla-get-ownerid (car sel))))
  ; (setq unnamed_block (vla-add (vla-get-blocks adoc)(vlax-3d-point '(0. 0. 0.)) "*U"))
   (setq unnamed_block (vla-add (vla-get-blocks adoc)(vlax-3d-point inspt) "*U"))
   (foreach x sel
     (setq oname (strcase (vla-get-objectname x)))
     (cond ((member oname '("ACDBVIEWPORT" "ACDBATTRIBUTEDEFINITION" "ACDBMTEXT" "ACDBTEXT")) nil)
    ((= oname "ACDBBLOCKREFERENCE")
     (vla-InsertBlock unnamed_block
       (vla-get-insertionpoint x)(vla-get-name x)
       (vla-get-xscalefactor x)(vla-get-yscalefactor x)
       (vla-get-zscalefactor x)(vla-get-rotation x))
     (setq blk (cons x blk)))
    (t (setq obj (cons x obj)))));_foreach
       (setq lay  (vla-item lays (getvar "CLAYER")))
       (if (= (vla-get-lock lay) :vlax-true)(progn (vla-put-lock lay :vlax-false) (setq loc (cons lay loc))))
    (if obj (progn (vla-copyobjects (vla-get-activedocument (vlax-get-acad-object))
             (vlax-make-variant (vlax-safearray-fill
                 (vlax-make-safearray vlax-vbobject (cons 0 (1- (length obj))))
                 obj)) unnamed_block)))
   (setq obj (append obj blk))
   (if obj (progn
         ;(setq tmp_blk (vla-insertblock csp (vlax-3d-point '(0. 0. 0.))(vla-get-name unnamed_block) 1.0 1.0 1.0 0.0))
             (setq tmp_blk (vla-insertblock csp (vlax-3d-point inspt)(vla-get-name unnamed_block) 1.0 1.0 1.0 0.0))
         (vla-GetBoundingBox tmp_blk 'MinPt 'MaxPt)  ;_??????? ?????
              (setq MinPt (vlax-safearray->list MinPt) MaxPt (vlax-safearray->list MaxPt)
      DS (max (distance MinPt (list (car MinPt)(cadr MaxPt)))
       (distance MinPt (list (car MaxPt)(cadr MinPt))))
             DS (* 0.2 DS) ;1/5
      DS (max DS 10) MinPt (mapcar '- MinPt (list DS DS))
                    MaxPt (mapcar '+ MaxPt (list DS DS)))
(lib:Zoom2Lst (list MinPt MaxPt))(setq sset (ssget "_C" MinPt MaxPt))
(if sset (progn (setvar "OSMODE" 0)
     (setq hiden (mapcar 'vlax-ename->vla-object(vl-remove-if 'listp (mapcar 'cadr (ssnamex sset))))
    hiden (vl-remove tmp_blk hiden))
     (mapcar '(lambda(x)(vla-put-Visible x :vlax-false)) hiden)
     (setq pt (mapcar '+ MinPt (list (* 0.5 DS)(* 0.5 DS))))
     (vl-cmdf "_.RECTANG" (trans MinPt 0 1)(trans MaxPt 0 1))
     (setq pl (vlax-ename->vla-object(entlast)))
     (setq sc (1-(vla-get-count csp)))
     (if (VL-CATCH-ALL-ERROR-P (VL-CATCH-ALL-APPLY '(lambda ()
        (vl-cmdf "_-BOUNDARY" (trans pt 0 1) "")
             (while (> (getvar "CMDACTIVE") 0)(command "")))))
     (if isRus (princ "\n?? ??????? ????????? ??????")(princ "\nIt was not possible to construct a contour")))
     (setq ec (vla-get-count csp))
       (while (< sc ec)(setq ret (append ret (list (vla-item csp sc))) sc(1+ sc)))
     (setq ret (vl-remove pl ret))
     (mapcar '(lambda (x)(vla-Erase x)(vlax-release-object x))(list pl tmp_blk))(setq pl nil tmp_blk nil)
     (setq ret (mapcar '(lambda ( x / mipt)(vla-GetBoundingBox x 'MiPt nil)  ;_??????? ?????
                (setq MiPt (vlax-safearray->list MiPt))(list MiPt x)) ret))
     (setq ret (vl-sort ret '(lambda (e1 e2)(< (distance MinPt (car e1))(distance MinPt (car e2))))))
     (setq pl (nth 1 ret) ret (vl-remove pl ret)) (mapcar 'vla-erase (mapcar 'cadr ret))
     (mapcar '(lambda(x)(vla-put-Visible x :vlax-true)) hiden)
     (foreach x loc (vla-put-lock x :vlax-true))
     (if pl (progn (initget  "Yes No")
     (if (= (getkword (if isRus "\n??????? ???????? [Yes/No] <No> : " "\nDelete objects? [Yes/No] <No> : ")) "Yes")
        (mapcar '(lambda (x) (if (vlax-write-enabled-p x)(vla-Erase x))) obj)))
(if isRus (princ "\n?? ??????? ????????? ??????")(princ "\nIt was not possible to construct a contour")))))))
    (VL-CATCH-ALL-APPLY '(lambda ()(mapcar 'vlax-release-object
   (list unnamed_block tmp_blk csp blks lays))))));_if not
 (foreach x loc (vla-put-lock x :vlax-true))(setvar "OSMODE" osm)
 (vla-endundomark adoc)(vlax-release-object adoc)(princ))

 

I thought that I could take only what i needed from it as it works just fine with an end user only this part but I might be missing something that makes it able to lunch in a Script.

Link to comment
Share on other sites

I don't think this will ever work in a script : (ssget) in this form requires a user input so either you must include this input in your script or use (ssget "w" '( 0 0) '(10 10)) or with a filter with the "X" option. But I suppose you could do something like :

(load "makeboundary")  ; load appie
(c:makeboundary)       ; run appie
all                    ; select all
                       ; end selecting with empty line
no                     ; delete original object?
.qsave                 ; save your drawing

 

pfff light's out for me for a moment... the flu... bummer...

 

p.s.

Lee has some boundary lisps on his site like : http://www.lee-mac.com/outlineobjects.html

Edited by rlx
Link to comment
Share on other sites

7 hours ago, rlx said:

I don't think this will ever work in a script : (ssget) in this form requires a user input so either you must include this input in your script or use (ssget "w" '( 0 0) '(10 10)) or with a filter with the "X" option. But I suppose you could do something like :


(load "makeboundary")  ; load appie
(c:makeboundary)       ; run appie
all                    ; select all
                       ; end selecting with empty line
no                     ; delete original object?
.qsave                 ; save your drawing

 

pfff light's out for me for a moment... the flu... bummer...

 

p.s.

Lee has some boundary lisps on his site like : http://www.lee-mac.com/outlineobjects.html

I try it but never manage to make it work as I wish it would... Finally with my collegs we decided to pass our way on this and got our final drawing looking as we would like 🤗.

 

Now the only thing that is missing to make everything working fine is to find a way to add point at the corner of a surface / region... As it's not considered as a Polyline pwlin or a normal line it's not working. 😒 I'm kind of tired of working on this... I made Like tooooooooooooooo many post for different things for this one -_- 

Edited by Jord_91
Link to comment
Share on other sites

sometimes all the effort to create a lisp routine can be disproportionate to just some good old manual labour. And sometimes leaving a problem alone for a while can help to start with a fresh look. My work has more to do with electric signals so no complex drawings or drawing objects. Maybe post a drawing example with what you have and what you want it to become can show better your problem , excuse me , your challenge , so other (and brighter) people can post tips on how to tackle your problem. Odds are you're not the only / the first one to do what you want to do.

 

ever checked this link? : http://forums.augi.com/showthread.php?76768-OBTAINING-BOUNDARY-BOX-POINTS-OF-AN-OBJECT-IN-UCS

Edited by rlx
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...