TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: dussla on January 09, 2009, 06:30:26 AM

Title: can you fix this lsp ( slice solid with polyline)
Post by: dussla on January 09, 2009, 06:30:26 AM
this is  slice soild with polyline by russian cool man
but that didn;t work well
pls , fix them


;; local defuns
;; groupping the list
(defun group-by-num  (lst num / ls ret)
  (if (= (rem (length lst) num) 0)
    (progn
      (setq ls nil)
      (repeat (/ (length lst) num)
  (repeat  num
    (setq  ls
        (cons (car lst) ls)
    lst (cdr lst)))
  (setq ret (append ret (list (reverse ls)))
        ls  nil)))
    )
  ret
  )

;get polyline vertices

(defun get-vexs   (pline_obj / verts)
  (setq  verts (vlax-get pline_obj 'Coordinates)
  verts
        (cond
    ((wcmatch (vlax-get pline_obj 'Objectname)
        "AcDb2dPolyline,AcDb3dPolyline")
     (group-by-num verts 3)
     )
    ((eq (vlax-get pline_obj 'Objectname)
         "AcDbPolyline")
     (group-by-num verts 2)
     )
    (T nil)
    )
  )
  )
(vl-load-com)
;;main part
(defun C:SSP  (/ *error* acsp adoc con osmd sscon sspline vertices_list)

  (defun *error* (msg)
    (cond
      ((not msg))
      ((wcmatch (strcase msg) "*QUIT*,*CANCEL*"))
      (T (princ (strcat "\nError: " msg)))
    )
  (if osmd   (setvar "osmode" osmd))
  (vl-cmdf "ucs" "w")
  (vl-cmdf "-view" "swiso")
  (vla-regen adoc acactiveviewport)
  (vla-endundomark adoc)
    (princ)
  )

  (setq  adoc (vla-get-activedocument
         (vlax-get-acad-object)
         )
  acsp (vla-get-block
         (vla-get-activelayout adoc)
         )
  )
  (vla-startundomark adoc)
  (vl-cmdf "ucs" "w")

  (setq osmd (getvar "osmode"))
  (setvar "osmode" 0)
  (alert "\nSelect the solid first\nthan select the polyline")
  (if (and
  (setq sscon (ssget "+.:S:N" (list (cons 0 "3DSOLID"))))
  (setq sspline (ssget "+.:S:N" (list (cons 0 "POLYLINE")))))
    (progn
      (setq vertices_list
       (get-vexs
         (vlax-ename->vla-object
     (ssname sspline 0))))
      (vl-cmdf "slice" (ssname sscon 0) "" "3P" (trans (car vertices_list) 1 0)
         (trans (cadr vertices_list) 1 0)
         (trans (caddr vertices_list) 1 0)
         '(0. 0. -100000.));;<-- change on '(0. 0. 100000.) if you need to keep the upper section

      ))

  (alert "Delete unused section\n of sliced solid manually")
  (*error* nil)
  (princ)
  )
(prompt "\n=======================================================\n")
(prompt "\n\t\t***\tStart command with SSP\t***")
(prompt "\n=======================================================\n")
(prin1)
Title: Re: can you fix this lsp ( slice solid with polyline)
Post by: ElpanovEvgeniy on January 09, 2009, 05:01:33 PM
It is necessary to specify the author! The author is known at this forum...
fixo (http://www.theswamp.org/index.php?action=profile;u=617)
Title: Re: can you fix this lsp ( slice solid with polyline)
Post by: CAB on January 10, 2009, 08:25:57 PM
Thanks for the 'Heads Up' Evgeniy.

Doing a search on the net and the usual places I see Fixo I have not been able to find the original routine.
I was going to add a link to the routine.
Title: Re: can you fix this lsp ( slice solid with polyline)
Post by: Crank on January 11, 2009, 01:37:05 AM
[...]
I was going to add a link to the routine.
Here it is. (http://www.cadtutor.net/forum/showpost.php?p=28130&postcount=8)
Title: Re: can you fix this lsp ( slice solid with polyline)
Post by: ElpanovEvgeniy on January 11, 2009, 02:35:47 AM
original routine (http://www.caduser.ru/cgi-bin/f1/board.cgi?t=45332gk)
anycg = dussla
Title: Re: can you fix this lsp ( slice solid with polyline)
Post by: CAB on January 11, 2009, 07:29:14 AM
Thanks for the help fellas.  8-)
Title: Re: can you fix this lsp ( slice solid with polyline)
Post by: dussla on January 16, 2009, 03:58:15 AM
i tested this lisp  , but still didn;t work ~

pls can you test ?
Title: Re: can you fix this lsp ( slice solid with polyline)
Post by: fixo on January 19, 2009, 04:56:17 AM
i tested this lisp  , but still didn;t work ~

pls can you test ?
Your drawing is wrong
I got the following error message:
"Slicing plane does not intersect the selected solid"
So, you need first to change elevation proprty of the slicing polyline:
go to Properties dialog box and change elevation on 36.0
then run the edited version
Code: [Select]
;; local defuns
;; groupping the list
(defun group-by-num  (lst num / ls ret)
  (if (= (rem (length lst) num) 0)
    (progn
      (setq ls nil)
      (repeat (/ (length lst) num)
  (repeat  num
    (setq  ls
        (cons (car lst) ls)
    lst (cdr lst)))
  (setq ret (append ret (list (reverse ls)))
        ls  nil)))
    )
  ret
  )

;get polyline vertices

(defun get-vexs   (pline_obj / verts)
  (setq  verts (vlax-get pline_obj 'Coordinates)
  verts
        (cond
    ((wcmatch (vlax-get pline_obj 'Objectname)
        "AcDb2dPolyline,AcDb3dPolyline")
     (group-by-num verts 3)
     )
    ((eq (vlax-get pline_obj 'Objectname)
         "AcDbPolyline")
     (group-by-num verts 2)
     )
    (T nil)
    )
  )
  )
(vl-load-com)
;;main part
(defun C:SSP  (/ *error* acsp adoc con osmd plent sscon sspline vertices_list)

  (defun *error* (msg)
    (cond
      ((not msg))
      ((wcmatch (strcase msg) "*QUIT*,*CANCEL*"))
      (T (princ (strcat "\nError: " msg)))
    )
  (if osmd   (setvar "osmode" osmd))
  (vl-cmdf "ucs" "w")
  (vl-cmdf "-view" "swiso")
  (vla-regen adoc acactiveviewport)
  (vla-endundomark adoc)
    (princ)
  )

  (setq  adoc (vla-get-activedocument
         (vlax-get-acad-object)
         )
  acsp (vla-get-block
         (vla-get-activelayout adoc)
         )
  )
  (vla-startundomark adoc)
  (vl-cmdf "ucs" "w")

  (setq osmd (getvar "osmode"))
  (setvar "osmode" 0)
  (alert "\nSelect the solid first\nthan select the polyline")
  (if (and
  (setq sscon (ssget "+.:S:N" (list (cons 0 "3DSOLID"))))
  (setq sspline (ssget "+.:S:N" (list (cons 0 "*POLYLINE")))))
    (progn
      (setq vertices_list
       (get-vexs
         (vlax-ename->vla-object
     (setq plent (ssname sspline 0)))))
      (vl-cmdf "._slice" (ssname sscon 0) "" "_O" plent
         (trans '(0. 0. -100000.) 0 1);;<-- change on '(0. 0. 100000.) if you need to keep the upper section

      )))

  (*error* nil)
  (princ)
  )
(prompt "\n=======================================================\n")
(prompt "\n\t\t***\tStart command with SSP\t***")
(prompt "\n=======================================================\n")
(princ)

~'J'~
Title: Re: can you fix this lsp ( slice solid with polyline)
Post by: DEVITG on January 27, 2009, 04:20:13 AM
Maybe I'm wrong .
But I think Dussla want to slice the solid by the Z axis .

Like the wedge is a piece of hardboard , and the polyline the jig saw phat.

As I say,  maybe I wrong.

Here is how I think the slice had to be do.