Author Topic: How to insert an object via mid of two points (lisp file half.lsp)  (Read 22206 times)

calubax

  • Newbie
  • *
  • Posts: 15
    • View Profile
Hello Babacad team,
I would like to led the program calculate the point (The mid of two points) to insert an object, a block, line or something else in.
Therefor the lisp program (half.lsp) should start in between. For example - I have drawn two rectangles - now I want to insert an objekt right in the middle of two selected points from the two rectangles.

What I found is that the command structure not enables a user input like to led the Lisp program(attached) calculate the point.
Maybe it could be possible (maybe hopefully in this early babacad progamming state with just a few program line changes)

Another Point to all other Babacad users would be that they could if they tell about lisp programs they already succsessful tested with BabaCAD. That could be very helpful for the comunity.
Best wishes to all


babadmin

  • Administrator
  • Full Member
  • *****
  • Posts: 142
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #1 on: November 21, 2017, 03:04:06 pm »
I check it, and it works (one small bug is that first point cursor is 0,0, lisp does not get A point as a start, but it's just visual effect, result of mid point is correct).

You get mid point as list in result of function. Also, to run this as a lisp command in command line you have to add 'c:' in front of HALF function name in this lisp or run as lisp function directly in BabaCAD command line (using brackets), like this (HALF).

calubax

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #2 on: November 21, 2017, 04:56:01 pm »
Hello babadmin,
could you please write the changes that have to be written in the lisp file and attach it here? I wrote a c: after defun but unfortunatly not worked.

babadmin

  • Administrator
  • Full Member
  • *****
  • Posts: 142
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #3 on: November 21, 2017, 10:06:29 pm »
(Defun c:HALF (/ a b)
(SETQ A (GETPOINT "\nFirst Point ")
B (GETPOINT A "\nOther Point "))
(POLAR A (ANGLE A B)(/ (DISTANCE A B) 2)))

then appload, choose half.lsp and type half at command line. That's it.

Updated: I fixed bug in getpoint lisp function (reference point is ok now). Just go download latest Update 2 (21th November late night CETime) from http://www.babacad.com/ext
« Last Edit: November 21, 2017, 11:40:39 pm by babadmin »

calubax

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #4 on: November 22, 2017, 05:38:25 pm »
Hello babadmin,
I did the changes - if I want to insert a block via the half lisp ( selecting two different points for example a point of a rectangle and then another point of another rectangle the block still
inserts on the first selected point - the second point is not being asked for) - the half lisp will not jump into insertion process to takeover the calculation result.

The half lisp program should deliver the coordinats for a start point (object insertion point, line start for example.
Or did I misunderstand the Lisp function.
In Autocad something similar (m2P) makes this work.

Maybe in this could be in the following updates - if it is possible

babadmin

  • Administrator
  • Full Member
  • *****
  • Posts: 142
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #5 on: November 22, 2017, 08:01:41 pm »
Copy this to m2p.lsp file

(Defun HALF (/ a b)
(SETQ A (GETPOINT "\nFirst Point ")
B (GETPOINT A "\nOther Point "))
(POLAR A (ANGLE A B)(/ (DISTANCE A B) 2)))
(defun c:m2p (/)
(command "insert" "b1" (half) 1.0 0.0))


Block named 'b1' must exists in drawing before starting command 'm2p' in BabaCAD. I've tested this lisp with success.

calubax

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #6 on: November 23, 2017, 04:00:44 pm »
Yes, this works fine! - but in Autocad this function makes it possible to make much more than  just inserting a block.

So, if for example a line, point or something future input should work with the half lisp function of cause every input (line, rectangle, circle, point, xline an so on) has to get its on Half.lsp or m2p..... much work...

babadmin

  • Administrator
  • Full Member
  • *****
  • Posts: 142
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #7 on: November 23, 2017, 10:09:17 pm »
It can do all same in BabaCAD too. I just gave example with block insert (command "insert"), but you can use any command.
If you want use mid point for line, than put (command "line" (half) '(25 30) "") , and this will draw line with startPoint= [midpoint as output calculated from func 'half'] and lastPoint=[some point ex. 25,30], or you can put some other variable instead of exact value for second point.

calubax

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #8 on: November 24, 2017, 11:44:57 am »
Hello babadmin,
here with the attachment version (m2P.lsp) everything works fine.
Maybe that funktion better could be included globaly to the fetch functions that are already bulid in.
 What I have found is that if I erase the line that was created with the m2p funktion the startpoint of the line stays there (looks like a Point). This rest (that Point, startpoint) of the erased line must then separatly erased.


babadmin

  • Administrator
  • Full Member
  • *****
  • Posts: 142
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #9 on: November 24, 2017, 08:44:01 pm »
You have bug in your m2p.lsp cause your second point parameter is bad and third parameter must be "" (to specify end of command, as line command does not end until last space or enter key).

You have three parameters: (half) 0.0 0.0, but 0.0 0.0 must be enclosed in parenthesis like this '(0.0 0.0) or "0.0 0.0". Also, "line" command must have "" at the end. So, your m2p.lsp must look like this:

(Defun HALF (/ a b)
(SETQ A (GETPOINT "\nFirst Point ")
B (GETPOINT A "\nOther Point "))
(POLAR A (ANGLE A B)(/ (DISTANCE A B) 2)))
(defun c:m2p (/)
(command "line" (half) '(0.0 0.0) ""))

calubax

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #10 on: November 25, 2017, 12:45:08 pm »
hello babadmin,
the lisp changes had that result(m2ptest1.dxf). When deleting the line there is no startpoint
left -  thats ok, but that the line automatly ends at the 0,0 point is of cause not wanted.

My version of the lisp worked fine - but the thing with that point left after erasing the line (startpoint perhaps caused from the half comand? i donĀ“t know - it is not so good in large drawings - what is this point - at the moment there is no Point definded in the Program - what could it then be?)
(attachemts m2ptest1.dxf, m2p.lsp )

calubax

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #11 on: November 25, 2017, 01:04:21 pm »
here,drawing m2ptest2.dxf

babadmin

  • Administrator
  • Full Member
  • *****
  • Posts: 142
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #12 on: November 25, 2017, 08:40:00 pm »
I don't understand you quite well. You get (0,0) point cause it's second point parameter. If you want some other point, just change that. For example: (command "line" point1 point2 ""). point1 and point2 are variables or fix values as list '(x y).

You have to look at a command and how it's working in the command line. In same way you provide parameters for (command "commandName" param1 param2 ....). So, line has minimum two points as parameters. You can provide more points to generate more lines. At the end, there must be "" to tell that "line" command has to stop.

calubax

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #13 on: November 26, 2017, 05:07:22 pm »
Yes,  (command "line" point1 point2 "") would be the right way for this lisp. The result of the half lisp for the start point of the line, and then a free chosen point for the second point and then the "" to end the lisp.
I unfortunatly dont know how to fix it. Not realy much that I know about lisp programming.

babadmin

  • Administrator
  • Full Member
  • *****
  • Posts: 142
    • View Profile
Re: How to insert an object via mid of two points (lisp file half.lsp)
« Reply #14 on: November 26, 2017, 08:02:08 pm »
This is solution:

(Defun HALF (/ a b c d)
(SETQ A (GETPOINT "\nFirst Point ")
B (GETPOINT A "\nOther Point "))
(POLAR A (ANGLE A B)(/ (DISTANCE A B) 2)))
(defun c:m2p (/)
(setq c (half))
(setq d (getpoint "Line second point: "))
(command "line" c d ""))