To write MEGALINE.lsp

To write MEGALINE.lsp

Anonymous
Not applicable
825 Views
9 Replies
Message 1 of 10

To write MEGALINE.lsp

Anonymous
Not applicable

Hello everyone,

recently I was busy with the topic of Line and Polyline drawing.

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/draw-line-under-angle-work-bad-bad-an...

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/draw-line-specify-horizontal-length-n...

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/change-delta-x-and-or-delta-y-of-a-li...

 

So after we came up together with my errors I thught about writing one big lisp (such as marko_ribar did for "New/Scale?Delta Width-Length of selected Rectangles" here: http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/select-rectangles-to-change-their-len... which "joins" these lisps together.

I called it MEGALINE.

 

I thought how it would be working.

And I drew an algorithm with arrows and prompts.

 

What do you think about it?

 

For now I haven't write any lisps in which I ask the user to type one button to enter one option or enter another button to enter another option (I mean something like this: "Specify next point or [Undo/Close]: ").

But I think I will analyse marko_ribar's lisp for Rectangle's Dimension Changing I mentioned and I try to write this lisp.

 

But what I ask you for:

Please, have a look at the .pdf file in Attachments and tell me what do you think about this algorithm.

Do you think I should delete some steps? Or have you any idea what I could add? Meybe shuffle the order of these commands?

I am waiting for your remarks and proposes.

0 Likes
826 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

I am really sorry for yellow and light blue colours on MEGALINE. pdf.

Now I attach MEGALINE (2). pdf on which the colours are good. Texts are black and these yellow arrows I changed into green ones.

0 Likes
Message 3 of 10

Anonymous
Not applicable

Now I changed the position so the arrows don't cross each other.

See the .pdf file.

0 Likes
Message 4 of 10

Anonymous
Not applicable

At the end of the algorithm is "Select quadrant (one of our):. You can not understand it.

When we have given Angle and Length_X of the Line, we have four cases of position of 2nd point (pt2) in regard to the 1st point we picked (pt1):

1st case: pt2 is on the right and above pt1

2nd case: pt2 is on the left and above pt1

3rd case: pt2 is on the left and under pt1

4st case: pt2 is on the left and under pt1

 

On the end of the RECTANGLE -> Dimensions command, we choose one of four cases.

Is there possible to get something like this, but in MEGALINE lisp?

Please, let me know.

0 Likes
Message 5 of 10

Kent1Cooper
Consultant
Consultant

Pardon my skepticism, but it seems to me that you're creating a more complicated situation than if you just get your users to learn the ways of designating points relative to previous points with the relative-displacement symbol @, and use those as appropriate.  When I need a point three units to the right and two units down from the last point, I'd much rather just type "@3,-2" than answer a whole series of prompts about in what way I want to designate the next point, and give it each element of that separately, and the quadrant to do it in, and so on.  Even with the varieties that can't be entered as directly, I think I would find it easier to draw a Line at, say "@10<32" and then use Lengthen on it to get the length I want, than plow through all those mega-steps.  But one of the nice things about AutoCAD is that it is capable of accommodating many approaches to the same task.

 

What you are asking about regarding quadrants can certainly be done.  You would compare the X and Y coordinates of the second point with those of the first point [read about (car) and (cadr) functions], and depending on the combination of which of each coordinate is greater, the quadrant can be determined.  For example, if 'pt1' is the first point in a variable, and 'pt2' the second, and you want a 'quad' variable to be set to 1 through 4 for the 1st through 4th cases, one way of deciding would be:

 

(setq

  delta (mapcar '- pt2 pt1)

  dx (car delta)

  dy (cadr delta)

  quad

    (cond

      ((and (> dx 0) (> dy 0)) 1)

      ((and (< dx 0) (> dy 0)) 2)

      ((and (< dx 0) (< dy 0)) 3)

      ((and (> dx 0) (< dy 0)) 4)

      ((zerop dx) (... pt2 is directly above or below pt1...)); don't forget to account for these possibilities

      ((zerop dy) (... pt2 is directly to the right or left of pt1...))

    ); cond & quad

); setq

 

Or another way:

 

(setq

  ang (angle pt1 pt2)

  quad

    (cond

      ((< 0 ang (/ pi 2)) 1)

      ((< (/ pi 2) ang pi) 2)

      ((< pi ang (* pi 1.5)) 3)

      ((< (* pi 1.5) ang) 4)

      ((zerop ang) (...pt2 is to the right of pt1))

      ((= ang (/ pi 2)) (...pt2 is above pt1))

      ((= ang pi) (...pt2 is to the left of pt1))

      ((= ang (* pi 1.5)) (...pt2 is below pt1))

    ); cond & quad

); setq

 

There are certainly a variety of other ways to come to the same determination.

Kent Cooper, AIA
0 Likes
Message 6 of 10

Anonymous
Not applicable

"When I need a point three units to the right and two units down from the last point, I'd much rather just type "@3,-2" than answer a whole series of prompts about in what way I want to designate the next point, and give it each element of that separately, and the quadrant to do it in, and so on.  Even with the varieties that can't be entered as directly, I think I would find it easier to draw a Line at, say "@10<32" and then use Lengthen on it to get the length I want, than plow through all those mega-steps.  But one of the nice things about AutoCAD is that it is capable of accommodating many approaches to the same task."

 

Yes, but what would you do when you have downslope = 7% and you have to draw line which's Length_X =3000 mm?

Will you calculate it on the sheet or calculate it in Autocad's Calculator (Ctrl+8)?

 

These options, which are default in AutoCad (@3,-2 works even if both ORTHO and POLAR are OFF. @10<32 too, but at every time I use it I don't know between what Objects is this angle measured.), are good only in two cases: @3,-2 is good when you have given Length_X and Length_Y, and @10<32 only when you have Total)Length and Angle (Decimal Degrees - that depends on current AUNITS value. But we all prefer situation, when before using @10<32 we haven't to set System Variables. Didn't we?).

What's more, even if I would be forced to choose between @3,-2 and  lisp with two prompts, I would choose lisp. WHy? Because if @3,-2 would be good, I wouldn't give it up. I tried both options: @3,-2 and lisp. And for me lisp is faster way, because, you have to press buttons which you set for yourself. WHen you use this lisp all the time, you know its prompts, so you just type a number, Space (as Enter), number, Space, and that's the end.

And the situation looks completely other with @3,-2. you HAVE TO (yes, you didn;t set this key. And you can't assign to it another key. At least it seems to me so) press [Shift] and [2] - that's uncomfortable for me. And that only in order to being forced to diametrally change position of hand on keyboard to press [,] just after entering first of two required numbers. So at the beginning you have left hand on the keyboard's left side and you are forced to press two buttons - [Shift] and [2]. Then your hand types a number, goes on the right side to type [,], type second number, and press [Space] or [Enter].

 

In both methods we type two numbers - so that is no differrence. Difference is, that between typing number:

- in lisp method you press only [Space]

- in @ method your hand have to go from left to right, than either go back to press [Space] or it goes further to press [Enter].

Maybe if I have to draw six Lines with @ method, I probably would be able to resist it. But imagine you draw 900 Lines, every time using hand like if you play pingpong. Maybe that is too big hiperbolization 😉

 

In one thing I agree - I am such specify type of man, who likes to have all collect together in one. Sometimes it is cause for errors. That I hear from many my familiars.

And one more thing. I try to solve easy problems with great machines, so that my opinion about MEGALINE doesn't wonder me.

Sometimes I forgot about simple methods which are so good as these "bigger" methods.

I will end 1st degree of Civil Engineering and when I remember, that on the project of road I had to draw road with i=2% and it had 1300 m length, and I had not lisp which on ground of given Downslope in Percents and Length_X would draw a Line, and I had to count its Length_X on a sheet which I had to take with me... Only four letters express what I think about it: A.R.G.H! Something awful...

 

So, I think that there commands which draw Lines on ground of given i[%] or i[Delta_Y/Delta_X] are useful, and that was point on which I started thinking about creating MEGALINE.lsp.

 

Thank you for your notices.

0 Likes
Message 7 of 10

Anonymous
Not applicable

I noticed that there is problem if Xpt1 = Xpt2, when I made RTREFPOI. lsp (or maybe that was the other one? I don't know now) And I made other command, which asks not to pick two points (pt1 and pt2, on gound of their coordinates I counted ang = atan (DY/DX)), but which uses getangle. It have no problem with zero in denominator, but it has the other one. It's value you have to convert from radians to degrees.

 

And the most imprtant thing: Great thanks for revealing code for "Select quadrant of drawn Line". I will try it.

0 Likes
Message 8 of 10

Anonymous
Not applicable

You are right, that sometimes the user prefers the single command instead of few command in one lisp.

For example, marko_ribar's RECEDIT lisp is too big for me.

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/select-rectangles-to-change-their-len...

 

I will rewrite his lisp into three separate lisps; each for one of three separate options (New/Scale/Delta).

And in each of them I change the case of selection set "Select Single Rectangle: " to "Select Rectangle(s): ".

 

So this depends of the user; every has different feelings about what to use.

0 Likes
Message 9 of 10

Anonymous
Not applicable

Dear Kent1Cooper,

thank you for showing me how would look expression for these four cases look like.

I think, that there's no need to use them, if we pick two points, because they determine the only one direction in which we would like to draw a line.

We could use 'getangle' which won't making problems with the case of XptL1-XptL2=0.

But they will be very useful in lisp like this: "Specify Angle and Length_X of Line to draw."

And in this case we will not need the case for XptL1-XptL2=0, because we won't pick two points in order to determine Endpoints of Line to be drawn.

I am very interested in how will be built this lisp:

 

; QNGX = Line aNGle length_X
(defun c:QNGX
 (/ ptL1 Ang Len_X Len_Y Len ptL2)
 (setvar "cmdecho" 0)
 (setq ptL1 (getpoint "\nSpecify First Point of Line: "))
 (command "_LINE" ptL1)
 (while
  (setq Ang (getangle "\nTYPE ANGLE (in decimal Degrees) value, OR PICK two Points to define it: ")) 
  (princ "\n(Before value type '+' to go right, and '-' to go left.)")
  (setq Len_X (getdist "\nTYPE Length_X of the Line, OR PICK two Points to define it: "))
  (setq Len_Y (* 
   (/ (sin Ang) (cos Ang))
   Len_X)
  )
  (setq Len
   (sqrt
    (+ (* Len_X Len_X) (* Len_Y Len_Y))
   ); sqrt
  ); Len
  (setq ptL2 (polar ptL1 Ang Len))
  (command ptL2)
  (setq ptL1 ptL2)
 ); while
);defun

 

after we add the option "Select Quadrant" to it. 

 

I think we will have to modify it to get four cases:

Case 1: (setq ptL2 (polar ptL1 Ang         Len))

Case 2: (setq ptL2 (polar ptL1 Ang+90   Len))

Case 3: (setq ptL2 (polar ptL1 Ang+180 Len))

Case 4: (setq ptL2 (polar ptL1 Ang+270 Len))

But I don't know what "plaster" use to join these four "bricks" which I have...

 

Could somebody please tell me it?

0 Likes
Message 10 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

after we add the option "Select Quadrant" to it. 

 

I think we will have to modify it to get four cases:

Case 1: (setq ptL2 (polar ptL1 Ang         Len))

Case 2: (setq ptL2 (polar ptL1 Ang+90   Len))

Case 3: (setq ptL2 (polar ptL1 Ang+180 Len))

Case 4: (setq ptL2 (polar ptL1 Ang+270 Len))

But I don't know what "plaster" use to join these four "bricks" which I have...

....


 

QuadrantSlopes.png


If my assumption about what you mean by the slope going into the four quadrants is correct, (cond) is a good "mortar" [better word for it than "plaster"] for your "bricks." If the quadrant designation is stored in a 'quad' variable using the four quadrant numbers [as in my earlier Reply], then something like this should do it:
(setq ptL2
  (polar
    ptL1
    (cond
      ((= quad 1) ang)
      ((= quad 2) (- pi ang))
      ((= quad 3) (+ pi ang))
      ((= quad 4) (- (* pi 2) ang))
    ); cond
    Len
  ); polar
); setq
But that's not the only way -- here's another:
(setq ptL2
  (polar
    ptL1
    (nth (1- quad) '(ang (- pi ang) (+ pi ang) (- (* pi 2) ang)))
    Len
  ); polar
); setq
If, however, my assumption is incorrect, it can be simpler -- just multiply 90 degrees by one less than the 'quad' value, and add that product to the 'ang' variable:
(setq ptL2 (polar ptL1 (+ ang (* (/ pi 2) (1- quad))) Len))
[Pardon the excessive line spacing -- it's not my fault.  For some reason, the "system" won't space them closer at the moment.]
Kent Cooper, AIA
0 Likes