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

Struggling to draw a line

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
borderliner
693 Views, 4 Replies

Struggling to draw a line

Hi, my next little problem (thank god for forums - I'd have to paint walls for a living without them).

 

I've written my first little Lisp function.

What it's for is drawing a simple borehole profile that can then be used to draw stylized cross sections on top of it.

 

Upon start the lisp, pick a point on screen (to get the X coordinate [x1 below]), then enter ground level at the command line [g1 below], then enter as many thicknesses as are present in the borehole log (will vary, but typically between 3-12). These I added to a list, because that seemed to make sense when I did it.

 

What I want it to do then is draw a pline from x1, g1 down to the next point (x1,g1 minus the 1st thickness), then the next (x1,g1 minus the 2nd thickness) etc., to the bottom of the borehole.

 

Then my CAD guys can sit there, and using the borehole logs, enter the values of the boreholes and it draws them on the screen, making it easy to join th dots.

 

It might be good if it placed a Acad point at each point as well, but I'm not overly bothered about that at the minute.

 

Here's my attempt so far.

 

(prompt "Type 'e1' to run...")

(defun c:e1 ( / )

(command "graphscr") (setq x1 (getpoint "\nPick insertion point:")) (setq x1a (car x1))

(initget (+ 1 2 4))   (setq g1 (getreal "\nEnter ground elevation: "))

(initget (+ 1 2 2)) (setq lvllist nil )   (while   (setq lvl (getreal "\nEnter layer thickness <Exit>: "))   (setq lvlList (append lvllist (list lvl))) )

(princ) )

 

 

Thanks for any help.

 

4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: borderliner

You could do that without a routine [minus the Point entity option], using the fact that a next point in any drawing or editing command can be determined by "aiming" the cursor in the direction you want it to be from the last point, and giving it a distance.

 

Turn Ortho on, and Osnap off.  Start a Line or Pline command and give it a starting point representing the Ground elevation.  Pull the cursor significantly downward, so the rubber-band line is going down vertically, by anything more than the overall boring depth.  Then just type in the thicknesses of the layers in order going downward, and it will make Lines or Polyline segments of those lengths in sequence.

Kent Cooper, AIA
Message 3 of 5
borderliner
in reply to: borderliner

Yeah, I realize that, but this is just part of what I'm hoping for in the end.

Thx.

Message 4 of 5
Kent1Cooper
in reply to: borderliner


@borderliner wrote:

....

Upon start the lisp, pick a point on screen (to get the X coordinate [x1 below]), then enter ground level at the command line [g1 below], then enter as many thicknesses as are present in the borehole log (will vary, but typically between 3-12). These I added to a list, because that seemed to make sense when I did it.

 

What I want it to do then is draw a pline from x1, g1 down to the next point (x1,g1 minus the 1st thickness), then the next (x1,g1 minus the 2nd thickness) etc., to the bottom of the borehole.

.... 

It might be good if it placed a Acad point at each point as well, but I'm not overly bothered about that at the minute.

.... 

(prompt "Type 'e1' to run...")

(defun c:e1 ( / )

(command "graphscr") (setq x1 (getpoint "\nPick insertion point:")) (setq x1a (car x1))

(initget (+ 1 2 4))   (setq g1 (getreal "\nEnter ground elevation: "))

(initget (+ 1 2 2)) (setq lvllist nil )   (while   (setq lvl (getreal "\nEnter layer thickness <Exit>: "))   (setq lvlList (append lvllist (list lvl))) )

(princ) )

.... 


Any reason not to permit 0 or negative values for g1?  You might do borings in Death Valley....  Also, I think you mean (+ 1 2 4) in the second (initget) [as written, it would permit 0, because the 2 and 2 add up to a 4, leaving no 2 bit in the result].  But for that second one, you don't want the 1 bit in there, because then it won't accept Enter to take the <Exit> option.

 

Also consider whether to get the ground level from a screen pick instead of an entered number [you could get both x1a and g1 from the same start-point pick], if that works with your process.  But keeping with most of what you have....

 

You would need your second (initget) repeated for every (getreal) [or (getdist) that I used below] request, so it needs to be built into the loop.  My approach would be to have it draw the Lines and place the Points as the layer thicknesses are entered, rather than afterwards from the list, so the User can see it progressing.  For instance, after getting g1, try something like this [untested]:

....

(setvar 'osmode 0)

(setvar 'lastpoint (list x1a g1 0)); will become start of Line series

(setq lvllist nil); or just localize the variable and omoit this

(initget (+ 2 4))

(while

  (setq lvl (getdist "\nEnter layer thickness <Exit>: "))

    ;;; using getdist allows option of on-screen pick, or different formats e.g. feet-inches-fractions

  (setq lvlList (append lvllist (list lvl))); for whatever other use(s) later

  (command

    "_.line" "@" (polar (getvar 'lastpoint) (* pi 1.5) lvl) ""

    "_.point" "@"

  ); command

  (initget (+ 2 4)); for the next one

); while

....

 

You could include the (initget)s fully inside the (while) loop, rather than have the first one before it, though it's a little more complicated:

 

(while

  (and

    (not (initget (+ 2 4))); [in (not) wrapper because (initget) returns nil]

    (setq lvl (getdist "\nEnter layer thickness <Exit>: "))

  ); and

  (setq lvlList (append lvllist (list lvl)))

  (command

    "_.line" "@" (polar (getvar 'lastpoint) (* pi 1.5) lvl) ""

    "_.point" "@"

  ); command

); while

Kent Cooper, AIA
Message 5 of 5
borderliner
in reply to: Kent1Cooper

Death Valley, yeah right. I'm north of the border - Alberta. Nothing negative here, apart from the temperature .Smiley Happy

 

Like I said it's my first time with Lisp, so I'll have to read through and look-up what you've done.

As I understood it, the initget thing was just a way of limiting what the response could be. I'll investigate further.

 

The way the cross section will be drawn is that you draw a line on a plan of the site, through the boreholes of interest. Placing ticks along it where the boreholes appear.

Then you straighten out the line, and move it so the left of the line is at a X coordinate of zero.

Then rotate each segment to 0, so you end up with a line, with ticks on it showing where the boreholes land.

 

We then draw a vertical line down, over the elevational range of interest (typically in Alberta somewhere in the 600-800 mAGL). So you basically end up with a load of vertical lines, spaced out correctly, cover the elevational range.

 

That's where picking any point on a vertical line comes from (quickest way to get the X coordinate). And it's easier to type in the ground elevation to start with, as it's in the borehole log, getting the X and Y to start the line.

 

I realized that it should probably draw the line as it went, I just didn't know how to do it. It would provide instant feedback for the drafter.

 

I'll go through your suggestions tonight, when the big-boss isn't walking around.

 

Thanks though.

 

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

Post to forums  

Autodesk Design & Make Report

”Boost