Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create a closed polyline and convert it to region.

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
bcorvera
2686 Views, 6 Replies

Create a closed polyline and convert it to region.

Hi Good day,

 

I just register here, and I dont know yet how to post a topic. so  i just make a reply to you answer to one of question that similiar to my mine. 

I'm trying to look for a LISP command where i will create a closed polyline with 4 sides in different angles. then convert it to region. 


Edited by
Discussion_Admin

6 REPLIES 6
Message 2 of 7
hmsilva
in reply to: bcorvera

Welcome to the Autodesk Discussion Groups, bcorvera!

 

As a demo:

(defun c:test ( / lst pt)
  (while
    (setq pt (getpoint "\nPick point: "))
     (if (= lst nil)
       (setq lst (list Pt))
       (setq lst (append (list pt) lst))
     )
  )
  (if lst
    (progn
      (command "_.pline")
      (foreach pt lst (command pt))
      (command "c")
    )
  )
  (command "region" (entlast) "")
  (princ)
)

HTH

Henrique

EESignature

Message 3 of 7
Kent1Cooper
in reply to: bcorvera


@bcorvera wrote:

....

I'm trying to look for a LISP command where i will create a closed polyline with 4 sides in different angles. then convert it to region. 
....


Are the different angles what the User would specify, rather than [for example] four point locations picked?  If so, it would also need something to determine the length of at least the first segment, or an overall length, or something.  It could probably calculate the lengths of segments under some circumstances, but maybe not all, depending on how the angles relate to each other.  [I'm assuming it would all be line segments, with no arc segments.]

Kent Cooper, AIA
Message 4 of 7
bcorvera
in reply to: hmsilva

Thanks hmsilva!

 

This is great,

 

I'm doing a lot of this in my work. Its save me a lot of time rather doing it manually.

 

I see the syntax is very complicated. what I know in lisp right now is just very basic.

 

 

 

Thanks,

Message 5 of 7
hmsilva
in reply to: bcorvera

You're welcome, bcorvera.

 

Regarding your lisp skill's, you are in the right place, there a bunch of people here that can help you, just try to write your codes, and when you have doubts, just ask...

 

Henrique

EESignature

Message 6 of 7
Kent1Cooper
in reply to: bcorvera


@bcorvera wrote:

.... 

I see the syntax is very complicated. what I know in lisp right now is just very basic.

....


It can certainly be done more basically, if you prefer [there are usually a number of different ways to do just about anything.]  For instance, if as you said originally they're always four-side Polylines, and you can rely on the User to always actually pick four points, without typing in any option choices or anything, you can do as little as this:

 

(command

  "_.pline" pause pause pause pause "_close"

  "_.region" "_last" ""

)

 

You can of course elaborate on that to do things like force the Polyline width to 0 if you're not sure it will be [it doesn't matter to the Region command, but you might want it to be, visually], add prompting, and a whole variety of other possibilities.

 

Also, look into the DELOBJ System Variable, which will give you a choice about whether the Polyline remains in the drawing after the Region command.

Kent Cooper, AIA
Message 7 of 7
Lee_Mac
in reply to: bcorvera

Here is an alternative method, using the ActiveX (COM) component of Visual LISP:

 

(defun c:myreg ( / cnt lst obj ocs spc vtx )
    (cond
        (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (getvar 'clayer))))))
            (princ "\nCurrent layer locked.")
        )
        (   (null (car (setq lst (list (getpoint "\nSpecify point 1: "))))))
        (   (progn
                (setq cnt 2)
                (while
                    (and
                        (< cnt 5)
                        (setq vtx (getpoint (car lst) (strcat "\nSpecify point " (itoa cnt) ": ")))
                    )
                    (setq lst (cons vtx lst)
                          cnt (1+ cnt)
                    )
                )
                (= cnt 5)
            )
            (setq ocs (trans '(0.0 0.0 1.0) 1 0 t))
            (setq spc
                (vlax-get-property
                    (vla-get-activedocument (vlax-get-acad-object))
                    (if (= 1 (getvar 'cvport))
                        'paperspace
                        'modelspace
                    )
                )
            )
            (setq obj
                (vlax-invoke spc 'addlightweightpolyline
                    (apply 'append
                        (mapcar
                            (function
                                (lambda ( x )
                                    (mapcar '+ (trans x 1 ocs) '(0.0 0.0))
                                )
                            )
                            (reverse lst)
                        )
                    )
                )
            )
            (vla-put-closed obj :vlax-true)
            (vlax-invoke spc 'addregion (list obj))
            (vla-delete obj)
        )
    )
    (princ)
)
(vl-load-com) (princ)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost