The function of drawing squares on LWPOLYLINE

The function of drawing squares on LWPOLYLINE

Anonymous
Not applicable
1,392 Views
14 Replies
Message 1 of 15

The function of drawing squares on LWPOLYLINE

Anonymous
Not applicable

Sir,

Can I get a lisp programme The function of drawing squares on LWPOLYLINE sections with a side length equal to the length of individual segments

0 Likes
Accepted solutions (1)
1,393 Views
14 Replies
Replies (14)
Message 2 of 15

ВeekeeCZ
Consultant
Consultant

@Anonymous , welcome to the forums!

Start with posting dwg example how desired result should look like. We need to see what you mean by "put squares on polyline"

0 Likes
Message 3 of 15

Anonymous
Not applicable

I think this should be probably a result of the function.  Put squares on polyline means the function should draw it on polyline with the lenght of segments. When you draw polyline that has got two segments funkction should draw two squares. 

0 Likes
Message 4 of 15

hak_vz
Advisor
Advisor
Accepted solution

I hope this works for you.

(defun c:rectfrompoly ( / pts e ent  clos ss i rect p1 p2 p3 p4 ang di *error*)
(defun *error* () (setvar 'cmdecho 1)(princ))
 (setvar 'cmdecho 0)
    (setq 
        e  
            (car(entsel "\n Select base polyline >"))
        ent 
            (entget e)
        clos 
            (cdr (assoc 70 ent))
         i 0 
    )
    (repeat
        (length ent)     
            (if (eq (car (nth i ent)) 10)
                (setq 
                    pts 
                        (append pts (list (cdr (nth i ent))))
                )
            )
            (setq 
                i
                    (+ i 1)
            )
    )
    (if 
        (= clos 1)
            (setq
                pts 
                    (append pts (list(car pts)))
            )
    )
   (setq p1 (car pts) i 1)
   (while (< i (length pts))
   (setq p2 (nth i pts)
        di (distance p1 p2)
        ang (- (angle p2 p1) (/ pi 2.0))
        p3 (polar p2 ang di)
        p4 (polar p1 ang di)
        rect (list p1 p2 p3 p4)
    )
   (entmakex
      (apply 'append
        (cons
          (list
            '(0 . "LWPOLYLINE")
            '(100 . "AcDbEntity")
            '(100 . "AcDbPolyline")
            (cons 8 "0")
            (cons 90 (length rect))
            '(67 . 0)
            '(410 . "Model")
            '(62 . 3)
            '(70 . 1)
          )
          (mapcar 'list (mapcar '(lambda (a) (cons 10 a)) rect))
        )
      )
    )
   (if (= (rem i 2.0) 0) (command "mirror" (entlast) "" p1 p2 "y"))
   (setq p1 p2 i (+ i 1))
   )
   (setvar 'cmdecho 1)
   (princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 15

devitg
Advisor
Advisor

Please try to clear . I do not understand. 

As I can see there are 3 squares ,  the 2 and 3 correspond to polyline measure , but the firs no .  

 

The red dimension make 2 and 3 square , (green dim)  , but from where do come de first square ?

 

0 Likes
Message 6 of 15

hak_vz
Advisor
Advisor

I have edited my code so that it mirrors rectangles created over polyline once to on side and on next segment to other side. Without putting to much testing in what side rectangle should be created, you can mirror them "manually" if needed.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 15

dbroad
Mentor
Mentor

Looks like you are a student.  Is this a class programming assignment?  It's relatively easy to accomplish this goal if you don't have too many segments.  Investigate the polygon command with the edge option.

Architect, Registered NC, VA, SC, & GA.
Message 8 of 15

devitg
Advisor
Advisor

Nice way . 

 

0 Likes
Message 9 of 15

Anonymous
Not applicable

I think it works corectly, thank you very much. Can you tell me is the LWPOLYLINE and POLYLINE the same?

0 Likes
Message 10 of 15

hak_vz
Advisor
Advisor

@Anonymous wrote:

 Is the LWPOLYLINE and POLYLINE the same?


In Autocad we have two kinds of polyline objects.

Lwpolyline is a 2d polyline object that can have straight segments or arc segments, and it wasn't curved.

 

It is defined as a single object and it has all vertexes defined inside its definition. 

 

Old style polyline is a complex object that has subelements defined separately as a Vertex objects. It can be 2d or 3d object that use smoothing (spline)....

 

Here is how lwpolyline is defined and here how polyline is defined. Polyline subelements are defined as

 

DXF definitions for all drawing elements are here

 

I have used lwpolyline definitions with function entmakex to create lwpolyline object.

 

When you start drawing a polyline it is created as lwpolyline (if not defined differently in with system variables).

If you are not interested about how acad handles its objects internally, then this two object are same. From a coder perspective those are two different object. 

 

To find how some object is defined in a drawing you may use

(defun c:showsel () (entget (car (entsel "\nSelect drawing pobject >"))))

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 11 of 15

devitg
Advisor
Advisor

As per  Dbroad tip , I did it by other way 

 

;;****************************************************************
;; Design by Gabo CALOS DE VIT from CORDOBA ARGENTINA
;;;    Copyleft 1995-2020 by Gabriel Calos De Vit ; DEVITG@GMAIL.COM    
;;
;; Hecho por  Gabo CALOS DE VIT de CORDOBA ARGENTINA
;;;    Copyleft 1995-2020 por Gabriel Calos De Vit 
;; DEVITG@GMAIL.COM 

;;;;-*******************************************************************************************************************************
;;;Marc'Antonio Alessi, Italy - http://xoomer.virgilio.it/alessi

(DEFUN ALE_ENTSELFILTER  (PRMSTR FLTLST / FLGSLT ENTNAM) ;-01
  (SETVAR "ERRNO" 0)
  (PRINC "\n_ ")
  (PROMPT (SETQ PRMSTR (STRCAT "\n" PRMSTR ": ")))
  (IF
    (WHILE (NOT FLGSLT)
      (IF (SETQ ENTNAM (SSGET "_:E:S" FLTLST))
        (NOT (SETQ FLGSLT T))
        (IF (= 52 (GETVAR "ERRNO"))
          (SETQ FLGSLT T)
          (PROGN
            (IF "acetutil.arx"
              (ACET-SYS-BEEP 16))
            (ALERT
 ;(STRCAT "\nUd no entendió lo que le pedí, pruebe de nuevo!" PRMSTR)
              (STRCAT "\nYou did not understood what I ask for , try it again!" PRMSTR)
              ) ;_ alert
            ) ;_ pron for error 
          ) ;_if 
        ) ;_if
      ) ;_while
     (NOT (PRINC "\nFunction cancelled. "))
     (SSNAME ENTNAM 0)
     ) ;_if
  ) ;_defundd

;;;;-*******************************************************************************************************************************

 ; initionn

(DEFUN RECTANG-FROM-POLY  (/
                           ACAD-OBJ
                           ADOC
                           END-PAR-PT
                           MODEL
                           PAR
                           POLY
                           POLY-A
                           POLY-A-ENDPARAM
                           POLY-A-STARTPARAM
                           SELECTIONSETS
                           START-PAR-PT)




  (VL-LOAD-COM)
  (SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) ;_ el programa ACAD 
  (SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ)) ;_ el DWG que esta abierto-
  (SETQ MODEL (VLA-GET-MODELSPACE ADOC))
  (SETQ SELECTIONSETS (VLA-GET-SELECTIONSETS ADOC))
;;; (code 8 (get-it))



  (SETQ POLY (ALE_ENTSELFILTER "Pick the Polyline  " '((0 . "*POLYLINE"))))
  (SETQ POLY-A (VLAX-ENAME->VLA-OBJECT POLY))

  (SETQ POLY-A-STARTPARAM (VLAX-CURVE-GETSTARTPARAM POLY-A))
  (SETQ POLY-A-ENDPARAM (VLAX-CURVE-GETENDPARAM POLY-A))

  (SETQ PAR (+ 0 POLY-A-STARTPARAM))
  (REPEAT (FIX POLY-A-ENDPARAM)
    (SETQ START-PAR-PT (VLAX-CURVE-GETPOINTATPARAM POLY-A PAR))
    (SETQ END-PAR-PT (VLAX-CURVE-GETPOINTATPARAM POLY-A (1+ PAR)))
    (VL-CMDF "_polygon" 4 "e" START-PAR-PT END-PAR-PT)
    (SETQ PAR (1+ PAR))
    ) ;end REPEAT 
  ) ;end RECTANG-FROM-POLY


(DEFUN C:POLY-SQR  ()

  (RECTANG-FROM-POLY)
  )

(ALERT "\n Type POLY-sqr")





;|«Visual LISP© Format Options»
(180 2 1 0 nil "end of " 100 20 2 2 nil nil T nil T)
;*** DO NOT add text below the comment! ***|;
Message 12 of 15

hak_vz
Advisor
Advisor

@devitg 

Nice solution,  but as @dbroad predicted, we have been solving a homework assignment  🙂

There is a new post with very same formulation.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 13 of 15

devitg
Advisor
Advisor

Hi Hak_vz , I take it as my homework, I like to made lisp by VL. 

 

0 Likes
Message 14 of 15

Anonymous
Not applicable

Thank you very much for your help.

0 Likes
Message 15 of 15

hak_vz
Advisor
Advisor

I have also started to use  vlisp in my code lately. Have been using vlisp many years ago, but somehow I have forgotten a lots of stuff, actually never mastered it. On the other hand "plane vanilla" autolisp commands are hard to forget . To me vlisp is as complex as Common Lisp while  autolisp is more like scheme (but better).

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes