Jump to content

My first Autolisp project : Constractive Wall Layout


Recommended Posts

Posted

Hi

 

Im very exited to pronounce my first project in Autolisp. I know it much more than I can chew, but the reasonfor my excitement is that this program can save my hours or even days in my daily work.

 

I tried to make it ease to follow as much as I could. I write to commands in plain English, I draw and annotate all the steps and even publish a flowchart.

 

Program overview:

 

After dividing a total length of the wall to x number of segment (restricted to outcome to min length and max length of each segment (thanks marko)).

 

 

 

The program simply needs to examine the distance between the front and back elevation, and draw a wall (upground) and a base wall (underground)

 

 

Than drawing a rectangle from the lowest point to the wall (forming the wall) and then drawing the base wall depending on the distance between the front and the back elevation.

 


;** GET USER INFO **;

;get the start point 
;get the end point

;get the wall elevation line 
;get the front elevation line
;get the back elevation line
 

;** PROCESS DATA  **;

;divide the (total length) so the resulting (segment length) wont be more than (max length) and not less than (min length) 


;** DRAW **;

;Add vertices to (wall Line) every (Segment Length) units
;Add vertices to (Front Line) every (Segment Length) units
;Add vertices to (back Line) every (Segment Length) units


;loop as segments counts , offset every segment length
   ;get (front elevation line)  verts in (start point) x axes
   ;get (back elevation line) verts in (start point + segment leng) x axes

   ;Which vertex in which line has the lowest Y value in the 4 vertices
       ;if (front line) than Place a dim line between the lowest Y to a parallel vertex in (back line)
       ;if(back line) than Place a dim line between the lowest Y to a parallel vertex in (front line)


;**draw block**;

;draw a line from the lowest vertex to its other vertex
;draw a line in the y axes from the last vertex to the wall elevation vertex
;complete the rectangle

;**draw bases;
;if the dim is more than 0 and less than 50
   ;than offset the lower line 40 units
   ;and offset the lower line 60 units

any thought are welcome!

Drawing3.jpg

wall.jpg

Posted

hi

i wrote this code:

;** get user information **;

;get the start and end points, total length 
(defun c:main ( / strPt endPt totLng)
 (setq strPt (getpoint "\nStart point of line : "))
 (setq endPt (getpoint strPt "\nEnd point of line : "))
 (setq strPt (trans strPt 1 0) endPt (trans endPt 1 0))
 (setq totLng (distance strPt endPt))
 )

and this is the output i get after clocking the points:

 

Start point of line :

End point of line : 400.0

(i dont understand where 400 came from)

 

when i type !totLng

i get 0

i expect it to hold the distance,

why it happens?

 

Thanks

Shay

Posted

If your not using ucs's then code can be simpler ie if youir dwg is 2d only the forget trans

 

;get the start and end points, total length 
(defun c:main ( / strPt endPt totLng)
 (setq strPt (getpoint "\nStart point of line : "))
 (setq endPt (getpoint strPt "\nEnd point of line : "))
 (setq totLng (distance strPt endPt))
 )

 

if your using ucs but want in world co-ords then something like this

 

;get the start and end points, total length 
(defun c:main ( / strPt endPt totLng)
 (setq strPt (trans (getpoint "\nStart point of line : ") 1 0))
 (setq endPt (trans (getpoint strPt "\nEnd point of line : ") 1 0))
 (setq totLng (distance strPt endPt))
 )

Posted

Hi

 

i simplified the stracture of the code:

 

;get the start and end points, total length 
(defun c:main ( / strPt endPt totLng)
 (setq totLng (getTotalLength))
 )


(defun getTotalLength ( / strPt endPt totLng)
 (setq strPt (getpoint "\nStart point of line : "))
 (setq endPt (getpoint strPt "\nEnd point of line : "))
 (distance strPt endPt)
 )

should i use always local variables? what if another function needs the value of a previously evaluated variables?

 

Thanks

Shay

Posted

You have to collect all subtotals in main_list,

then Total result would be like this

(setq total (apply '+ main_list))

if you need to get the list of distances increased from the start

try this function

 
;; by VovKa 
(defun sumlist (lst / )
(if lst
(append (sumlist (reverse (cdr (reverse lst))))
(list (apply '+ lst)))
   ));if & defun

 

Usage:

 
(setq runned_totals (sumlist main_list))

Posted (edited)

Maybe change your main this way your totlong is not set as a local variable. Also dont need strpt endpt as they are local variables. Whilst this is not good programming start with () no variables set makes all global then go back and set locals as code progresses. Maybe also have a think about your defun really its doing 2 things getting two points plus distance I would be more inclined to use it as that 2xpts then do the distance as a local statement, you will probably want more simple routines like pick 3 points plus is 3rd perp to first two. There are more experts than me on use of variables I am sure they will help.

 

I use defuns all the time makes life much easier put all your common defuns in acaddoc.lsp then they are ready to use no need to code again in each program.

 

(defun c:main ()
(getTwopoints)
(setq totlng (distance pt1 pt2)) ; this way you can use pt1 & pt2 again else a defun (dp1p2)
;(setq totlng (dp1p2))
)

(defun getTwopoints ( )
 (setq strPt (getpoint "\nStart point : "))
 (setq endPt (getpoint strPt "\nEnd point : "))

)

(defun dp1p2 (pt1 pt2 / )
(distance pt1 pt2) 
)

Edited by BIGAL
Posted

Thanks BIGAL and fixo. ill bear it in mind when i get the main function to work. still have problems now ,

 

To put it simple, so far I got the total length from user and then have it divided (original code writen by marko_ribar), so now I know how many segments I have and each segment length .

 

Next step is to ask the user which line represents the wall and which lines representing the front, back and exist elevations (not sure how to store them)

 

than i want to destribute vertices along each line wtih "segment length" interval and find the lowest y coordinatein in each segment (original code written by pBe)

 

 

 

 

 

i got confused in 2 things:

  1. how i should bound the polylines names(back,front,etc) with their corresponding list of coordinates?
  2. how to get the lowest y coordinate every 4 points along the total length?

This is un-interrupter-able code I editedwith the help of the members of this great group, hope will be interrupter-ablecode in the near future :oops:

[font=Tahoma][color=#303030];get the start and end points, total length [/color][/font]
[font=Tahoma][color=#303030](defun c:main ( / strPt endPt totLng)[/color][/font]
[font=Tahoma][color=#303030]  (setq totLng (getTotalLength))[/color][/font]
[font=Tahoma][color=#303030]  (setq frontElv(getFrontElevation))[/color][/font]
[font=Tahoma][color=#303030]  (setq backElv(getBackElevation))[/color][/font]
[font=Tahoma][color=#303030]  (setq extElv(getExisttElevation))[/color][/font]
[font=Tahoma][color=#303030]  (setq frontElv(getWalltElevation))[/color][/font]
[font=Tahoma][color=#303030]  )[/color][/font]

[font=Tahoma][color=#303030](defun getTotalLength ( / strPt endPt totLng)[/color][/font]
[font=Tahoma][color=#303030]  (setq strPt (getpoint "\nStart point of line : "))[/color][/font]
[font=Tahoma][color=#303030]  (setq endPt (getpoint strPt "\nEnd point of line : "))[/color][/font]
[font=Tahoma][color=#303030]  (distance strPt endPt)[/color][/font]
[font=Tahoma][color=#303030]  )[/color][/font]
[font=Tahoma][color=#303030](defun getFrontElevation (/ frtele)[/color][/font]
[font=Tahoma][color=#303030]  (vl-load-com)[/color][/font]
[font=Tahoma][color=#303030]  (vlax-safearray->list[/color][/font]
[font=Tahoma][color=#303030]    (vlax-variant-value[/color][/font]
[font=Tahoma][color=#303030]      (vlax-get-property[/color][/font]
[font=Tahoma][color=#303030] (vlax-ename->vla-object frtele)[/color][/font]
[font=Tahoma][color=#303030] "Coordinates"[/color][/font]
[font=Tahoma][color=#303030]      )[/color][/font]
[font=Tahoma][color=#303030]    )[/color][/font]
[font=Tahoma][color=#303030]  )[/color][/font]
[font=Tahoma][color=#303030]  (defun getBackElevation (/ bckele)[/color][/font]
[font=Tahoma][color=#303030]  (vl-load-com)[/color][/font]
[font=Tahoma][color=#303030]  (vlax-safearray->list[/color][/font]
[font=Tahoma][color=#303030]    (vlax-variant-value[/color][/font]
[font=Tahoma][color=#303030]      (vlax-get-property[/color][/font]
[font=Tahoma][color=#303030] (vlax-ename->vla-object bckele)[/color][/font]
[font=Tahoma][color=#303030] "Coordinates"[/color][/font]
[font=Tahoma][color=#303030]      )[/color][/font]
[font=Tahoma][color=#303030]    )[/color][/font]
[font=Tahoma][color=#303030]  )[/color][/font]
[font=Tahoma][color=#303030]    (defun getExistElevation (/ extele)[/color][/font]
[font=Tahoma][color=#303030]  (vl-load-com)[/color][/font]
[font=Tahoma][color=#303030]  (vlax-safearray->list[/color][/font]
[font=Tahoma][color=#303030]    (vlax-variant-value[/color][/font]
[font=Tahoma][color=#303030]      (vlax-get-property[/color][/font]
[font=Tahoma][color=#303030] (vlax-ename->vla-object extele)[/color][/font]
[font=Tahoma][color=#303030] "Coordinates"[/color][/font]
[font=Tahoma][color=#303030]      )[/color][/font]
[font=Tahoma][color=#303030]    )[/color][/font]
[font=Tahoma][color=#303030]  )[/color][/font]
[font=Tahoma][color=#303030]      (defun getWallElevation (/ walele)[/color][/font]
[font=Tahoma][color=#303030]  (vl-load-com)[/color][/font]
[font=Tahoma][color=#303030]  (vlax-safearray->list[/color][/font]
[font=Tahoma][color=#303030]    (vlax-variant-value[/color][/font]
[font=Tahoma][color=#303030]      (vlax-get-property[/color][/font]
[font=Tahoma][color=#303030] (vlax-ename->vla-object walele)[/color][/font]
[font=Tahoma][color=#303030] "Coordinates"[/color][/font]
[font=Tahoma][color=#303030]      )[/color][/font]
[font=Tahoma][color=#303030]    )[/color][/font]
[font=Tahoma][color=#303030]  )[/color][/font]
[font=Tahoma][color=#303030](Defun destVerts ( /segleng)[/color][/font]
[font=Tahoma][color=#303030]  (if (and (setq pline (car (entsel "\nSelect Polyline:")))[/color][/font]
[font=Tahoma][color=#303030]           (eq (cdr (assoc 0 (entget pline))) "LWPOLYLINE")[/color][/font]
[font=Tahoma][color=#303030]           (setq int seglng)[/color][/font]
[font=Tahoma][color=#303030]           (setq in int)[/color][/font]
[font=Tahoma][color=#303030]      )[/color][/font]
[font=Tahoma][color=#303030]    (while (Setq pt (vlax-curve-getPointAtDist pline int))[/color][/font]
[font=Tahoma][color=#303030]      (setq ppt (vlax-curve-getparamatpoint pline pt))[/color][/font]
[font=Tahoma][color=#303030]      (vlax-invoke[/color][/font]
[font=Tahoma][color=#303030]        (vlax-ename->vla-object pline)[/color][/font]
[font=Tahoma][color=#303030]        'AddVertex[/color][/font]
[font=Tahoma][color=#303030]        (1+ (fix ppt))[/color][/font]
[font=Tahoma][color=#303030]        (list (car pt) (Cadr pt))[/color][/font]
[font=Tahoma][color=#303030]      )[/color][/font]
[font=Tahoma][color=#303030]      (setq int (+ int in))[/color][/font]
[font=Tahoma][color=#303030]    )[/color][/font]
[font=Tahoma][color=#303030]  )[/color][/font]
[font=Tahoma][color=#303030])[/color][/font]
[font=Tahoma][color=#303030])[/color][/font]

 

 

 

Thanks

Shay

Posted

A couple of suggestions

 

You only need vl-load-com at very start line 2 in your code.

 

You only need 1 get co-ords defun just set the returned value to the new variable name, you may want to include the 2nd part of the getco-ords which makes a list of the pline points.

 

[font=Tahoma][color=#303030] (setq backElv(getfrontElevation))[/color][/font]
[font=Tahoma][color=#303030]  (setq extElv(getfrontElevation))[/color][/font]
[font=Tahoma][color=#303030]  (setq frontElv(getfrontElevation))[/color][/font]

 

Regarding every 4th point min Y just use (nth J frontelev) and step J by 2 list is x y x y x y and just use a (if (

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...