Author Topic: Create Panels  (Read 5887 times)

0 Members and 1 Guest are viewing this topic.

AARYAN

  • Newt
  • Posts: 72
Create Panels
« on: September 01, 2012, 08:39:54 AM »
Hi All,

This is my first post in this Forum. I've gained so much of knowledge about CAD from this forum... Thanks to All of You...

I need your help and my request is.
I am trying to make a lisp routine which create Panels along Polyline for preparing Alignment Sheet, but I am stuck as I am not such a good programmer.
Below is the code so far I've made. I am not able to insert a loop in my routine because I am confused.
I am attaching a drawing too in which I've created Panels manually.
Its my humble request to all of you to please have a look at the drawing and help me achieve this.

Code: [Select]
(Defun C:CreatePanel ()
 
  (defun MakePanel (p1 p2 len wid Ang / tmpent widmid)
    (command "_Rectangle" p1 (strcat "@" (rtos len 2 16) "," (rtos wid 2 16)) "")
    (setq tmpent (entlast))
    (setq Tmplist (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget tmpent))))
    (setq widmid (list (car (car Tmplist)) (/ (+ (cadr (car Tmplist)) (cadr (cadddr Tmplist))) 2)))
    ;(command "_move" tmpent "" widmid p1)
    (command "_Rotate" tmpent "" widmid Ang)
    (command "_move" tmpent "" widmid p2)
    (princ))
 
  (defun dtr (a)           ; Degrees to Radians
(* pi (/ a 180.0)))
  (defun rtd (a)           ; Radians to Degrees
(/ (* a 180.0) pi))
     
  (defun *error* (msg)
    (if msg
      (princ (strcat "\nError! " msg))
    )
    (princ)
  )
;;-----------------=={ Group by Number }==--------------------;;
;;                                                            ;;
;;  Groups a list into a list of lists, each of length 'n'    ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  l - List to process                                       ;;
;;  n - Number of elements by which to group the list         ;;
;;------------------------------------------------------------;;
;;  Returns:  List of lists, each of length 'n'               ;;
;;------------------------------------------------------------;;
  (defun LM:GroupByNum (l n / r)
    (if l
      (cons
(reverse (repeat n
   (setq r (cons (car l) r)
l (cdr l)
   )
   r
)
)
(LM:GroupByNum l n)
      )
    )
  )
;;-----------------=={ Get Intersections }==------------------;;
;;                                                            ;;
;;  Returns a list of all points of intersection between      ;;
;;  two objects                                               ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  obj1, obj2 - VLA-Objects                                  ;;
;;------------------------------------------------------------;;
;;  Returns:  List of intersection points, or nil             ;;
;;------------------------------------------------------------;;
  (defun LM:GetIntersections (obj1 obj2)
    (LM:GroupByNum
      (vlax-invoke obj1 'IntersectWith obj2 acExtendnone)
      3
    )
  )
  (setq Plength (getreal "\nSpecify Panel Length:")
Pwidth (getreal "\nSpecify Panel Width:")
Overlap (getreal "\nSpecify Overlapping between Panels:");refer drawing
gap (getreal "\nSpecify gap between Route and First Panel:");refer drawing
  )
  (while (not
      (and (setq Kproute
(car (entsel "\nSelect Polyline Route:")))
   (eq "LWPOLYLINE"
        (cdr (assoc 0 (entget Kproute))))
  )))
  (setq Kprop (entget Kproute))
  (setq Coorlist (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) Kprop))); list of coordinates
  (setq Vertlength (length Coorlist)
FirstVert (nth 0 Coorlist)
SecondVert (nth 1 Coorlist)
FSAng (rtd (angle FirstVert SecondVert)); angle between first and second vertex
FScounterAng (angle SecondVert FirstVert); angle between second and first vertex
StartP (polar FirstVert FScounterAng gap))
  (MakePanel FirstVert StartP Plength Pwidth FSAng)
  (setq Panel (entlast));saves last rectangle
  (setq InterCheck (LM:GetIntersections (vlax-ename->vla-object Kproute) (vlax-ename->vla-object Panel)));check intersection between rec and route
  (princ))
« Last Edit: September 15, 2012, 02:34:53 AM by AARYAN »

BlackBox

  • King Gator
  • Posts: 3770
Re: Create Panels
« Reply #1 on: September 01, 2012, 03:42:39 PM »
Welcome to TheSwamp, Aaryan.

When posting someone else's code, you should be sure to properly accredit the author of the code you post, otherwise it may seem as though you're pirating someone else's work (which I do not believe you to be guilty of, in this case, as you are new).

Given that I recognize Lee's code, please read the Terms of Use available on his website, and correct the code in your post.

I've downloaded the drawing you posted, and will give it a look. If I can be of help, I will post back.
"How we think determines what we do, and what we do determines what we get."

DEVITG

  • Bull Frog
  • Posts: 480
Re: Create Panels
« Reply #2 on: September 01, 2012, 03:49:37 PM »
Further more than the good advice by REnderman, it  is a good etiquette forum  norm.

Your DWG as not a LWPOLYLINE , it have a POLYLINE , so your first WHILE statement will never be TRUE .
And such POLYLINE has not any dxf code 10

Quote
(-1 . <Entity name: 7efc5498>)
(0 . "POLYLINE")
(5 . "1B3")
(102 . "{ACAD_REACTORS")
(330 . <Entity name: 7efc5790>)
(102 . "}")
(330 . <Entity name: 7efc2cf8>)
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "0")
(62 . 1)
(100 . "AcDb2dPolyline")
(66 . 1)
(10 0.0 0.0 0.0)
(70 . 0)
(40 . 0.0)
(41 . 0.0)
(210 0.0 0.0 1.0)
(71 . 0)
(72 . 0)
(73 . 0)
(74 . 0)
(75 . 0)

So , you can not get the Coorlist by this   code line

Code: [Select]
  (setq Coorlist (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) Kprop))); list of coordinates



« Last Edit: September 01, 2012, 03:59:25 PM by DEVITG »
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

BlackBox

  • King Gator
  • Posts: 3770
Re: Create Panels
« Reply #3 on: September 01, 2012, 03:53:41 PM »
It appears that you're wanting to create PViewport Frames (i.e. Panels), along what appears to be an alignment (i.e. Center Line, Base Line, etc.).

This functionality is built-in for Civil 3D, but given that you're attempting to do this with code you are probably using vanilla AutoCAD, methinks (I could be wrong).

That said, rather than creating the geometry through calculations and entity creation, you might consider the MEASURE Command, using a standard Block definition for your 'panel' that would then be placed, and aligned with the selected polyline. Just a thought; it's certainly not a perfect solution.
"How we think determines what we do, and what we do determines what we get."

DEVITG

  • Bull Frog
  • Posts: 480
Re: Create Panels
« Reply #4 on: September 01, 2012, 04:38:15 PM »
Render Man, to use Meassure , was the  first thought , but how to make measure to start before the startpoint of the LWpline ?

See attached dwg
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

AARYAN

  • Newt
  • Posts: 72
Re: Create Panels
« Reply #5 on: September 02, 2012, 02:08:14 PM »
@RenderMan
I am extremely sorry for not posting the author name, that is because I didn't realize I must include the author name. Sorry to Mr.Lee Mac too.

@DEVITG
You pointed correctly. Even I thoguht of using measure command before starting the routine but I wanted not only to start the panel before polyline but also to save those panels to the varaiables.

Sorry for late posting. Can anyone help me or point me to the right direction

Best regards
Aaryan

DEVITG

  • Bull Frog
  • Posts: 480
Re: Create Panels
« Reply #6 on: September 02, 2012, 03:32:47 PM »
AARYAn, maybe it´s easy to extend the LWPOPILINE far beyond the left donw corner , and use the Measure.

Or better , say WHAT you need , and not HOW you think it can be do.

Location @ Córdoba Argentina Using ACAD 2019  at Window 10

AARYAN

  • Newt
  • Posts: 72
Re: Create Panels
« Reply #7 on: September 02, 2012, 10:06:56 PM »
Thanks DEVITG
What I think is, if we can find the vertex which comes next to the intersection of the first panel and route, then we can apply the same algo to them and create second panel and iterate the code until it does not find any intersection.

Regards

DEVITG

  • Bull Frog
  • Posts: 480
Re: Create Panels
« Reply #8 on: September 02, 2012, 10:14:57 PM »
Why to reinvent the wheel, just add a small line to the polyline and use  measure , then split the small part .
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

AARYAN

  • Newt
  • Posts: 72
Re: Create Panels
« Reply #9 on: September 02, 2012, 10:50:09 PM »
Yes we can, but what about the overlap between two panels. And how can I save those panels into some variables for further use.
Is it possible as per your opinion.

Regards

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Create Panels
« Reply #10 on: September 02, 2012, 10:52:42 PM »
Welcome to the Swamp AARYAN.

This is an incomplete routine that should get you started.
No more time today.

Code: [Select]
(Defun C:Panel (/ Plen Pwid overlap gap step pkpt pkpa strt end NextPt
                      Panels curve pk stparm dist)
 
  (defun MakePanel (p1 p2 len wid / tmpent widmid space)
   ;;  by CAB 03/22/2009
   ;;  Expects pts to be a list of 2D or 3D points
   ;;  Returns new pline object
   (defun makePline (spc pts / norm elv pline)
     (setq norm  (trans '(0 0 1) 1 0 T)
           elv   (caddr (trans (car pts) 1 norm))
     )
     (setq pline
       (vlax-invoke Spc 'addLightWeightPolyline
         (apply 'append
           (mapcar  '(lambda (pt)
              (setq pt (trans pt 1 norm))
              (list (car pt) (cadr pt)))       
             pts)))
     )
     (vla-put-Elevation pline elv)
     (vla-put-Normal pline (vlax-3d-point norm))
     pline
   )

  (setq Space
(if (= 1 (getvar "CVPORT"))
   (vla-get-PaperSpace (vla-get-activedocument (vlax-get-acad-object)))
   (vla-get-ModelSpace (vla-get-activedocument (vlax-get-acad-object)))
)
  )
   
    (setq ang1 (+ (angle p1 p2) (/ pi 2))
          ang2 (+ ang1 pi)
          wid  (/ wid 2.)
          )

    (setq pobj (makePline Space (list (polar p1 ang1 wid) (polar p1 ang2 wid)
                                      (polar p2 ang2 wid) (polar p2 ang1 wid))))
    (vla-put-Closed pobj :vlax-true)
    pobj
    )
 

 
 
  (setq Plen 250. ;(getdist "\nSpecify Panel Length:")
Pwid 75.0 ;(getdist "\nSpecify Panel Width:")
Overlap 25. ;(getdist "\nSpecify Overlapping between Panels:");refer drawing
gap 50. ;(getdist "\nSpecify gap between Route and First Panel:");refer drawing
        step 1
  )
  (while (not
      (and (setq curve (car (setq pk (entsel "\nSelect Polyline Route:"))))
   (member (cdr (assoc 0 (entget curve))) '("LWPOLYLINE""POLYLINE"))
  )))

  (setq pk   (cadr pk) ; picked point
        pkpt (vlax-curve-getclosestpointto curve pk) ; make sure point is on the curve
        pkpa (vlax-curve-getparamatpoint curve pkpt)
        strt (vlax-curve-getstartparam curve)
        end  (vlax-curve-getendparam curve)
  )
  ;;  Is start point at the beginning or end of pline?
  (if (< (vlax-curve-getdistatparam curve pkpa)
         (- (vlax-curve-getdistatparam curve end) (vlax-curve-getdistatparam curve pkpa)))
    (setq stparm   strt
          StartFlg t ; flag the pline direction
          dist     0.0)
    (setq stparm end
          step   (- step)
          dist   (vlax-curve-getdistatparam curve (vlax-curve-getendparam curve)))
  )

  ;;  Add the rectangles
  (while
    (progn
      (cond
        ((null NextPt) ; first point, first time through loop
         (setq NextPt (vlax-curve-getpointatdist curve (abs(- dist(- Plen Gap Overlap))))
               pa     (vlax-curve-getparamatdist curve  (abs(- dist(- Plen Gap Overlap)))))
         (setq Panels (list (MakePanel (polar (setq ps (vlax-curve-getpointatparam curve stparm)) (angle NextPt ps) Gap)
                             (vlax-curve-getpointatdist curve (abs(- dist(- Plen Gap)))) Plen Pwid)))
        )
        ((and (setq dist (vlax-curve-getdistatparam curve pa))
              (setq pa (vlax-curve-getparamatdist curve (+ (* step plen) dist))))
         (setq Pt (vlax-curve-getpointatparam curve pa))
         (setq Panels (cons (MakePanel NextPt Pt Plen Pwid) Panels))
         (setq pa (vlax-curve-getparamatdist curve (+ dist (* step (- plen Overlap)))))
         (setq NextPt (vlax-curve-getpointatparam curve pa))
         (if (null (setq dist (vlax-curve-getdistatpoint curve NextPt)))
           (princ)
           )
         t
        )
      )
    )
  )
  (princ))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

AARYAN

  • Newt
  • Posts: 72
Re: Create Panels
« Reply #11 on: September 03, 2012, 12:43:04 AM »
Thank You So much CAB.
I'll give it a try and let you know if any doubt..

Thanks and Regards

AARYAN

  • Newt
  • Posts: 72
Re: Create Panels
« Reply #12 on: September 03, 2012, 01:23:58 AM »
Thank You CAB,

It works great.
But as you said it is not complete, It is a pure Visual Lisp which bounces from my head and I think I cannot modify it as I am just an intermediate Autolisper.
I appreciate and thanks for your time, help and effort.
I will try my best to modify it and if I reach the destination I'll let you know.

Modifications required to complete this routine are as follows:
1, To create the last panel.
2, To rectify the error i.e the panel measures wrong length sometimes at the curve of the polyline.
3, Panel leaves the polyline when there is a sharp turn (like an edge).

Thanks and Best Regards
Aaryan.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Create Panels
« Reply #13 on: September 03, 2012, 07:30:12 AM »
You're welcome.
I may have some time later today.


You must develop rules on how you want to deal with pline segments that are too sharp a bend to stay within the defined panel.

Not sure why some panels would be too short.

The last panel should be easy to add.

Later

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Create Panels
« Reply #14 on: September 03, 2012, 07:47:11 AM »
Now that I'm waking up I see that my length will be wrong when the center line is curved because I used the travel distance along that line to get the length point.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.