Author Topic: Draw on user selected side of line or direction perpendicular to user line.  (Read 201 times)

0 Members and 1 Guest are viewing this topic.

Strydaris

  • Mosquito
  • Posts: 4
Hi Everyone,

Hoping someone here can help me out.
I am trying to write a lisp routine to preform, what I used to believe is a simple task, but its proving to be challenging.
That basic run down is like this.

User picks a point, then the corresponding text or Mtext associated with it.
User picks second point, then the corresponding text or Mtext associated with it.
The Lisp draws a temp line between the 2 points, gets the mid point.
Afterwards I want to be able to pick a direction perpendicular to the temp line to set the angle and side to which I am going to draw a polyline.
This is the part I am having trouble with.
The idea is that no matter which way I select the points, the user will always be in control of what side to draw the polyline on.

I have attached an image of what the end result I am trying to achieve.
The 2 selectable points would be the X and the 192.13 (bottom left) and X and the 192.19 (Bottom right)
Then the User would have something to select a direction perpendicular to the line created between those 2 points. The user would select the direction that the 3% arrow is pointing.
Then the Lisp would draw the cyan coloured polyline with the arcs in it. Arcs are always a 5m radius where the straight line portion is variable based on the length between the 2 points minus 10m.

The first part of my code looks like this. I just dont know where to take it from there. The last part where it does all the calcs is mostly worked out..
Also pardon my poor LISP coding. I mostly learn by cobbling things together and reading Lee Macs amazing lisps which 75% of them I dont understand.

Code: [Select]
(DEFUN C:RAPRN (/ *error* PT1 PT2 PT3 ELV1 ELV2 )
(vl-load-com)
  (setq blkname "BIGUMS")
    (setq acadobj    (vlax-get-acad-object)
adoc    (vla-get-ActiveDocument acadobj)
msp    (vla-get-ModelSpace adoc)
activeundo nil)
 
(setq swllayer "SWALE")
  (setq tmplayer "Defpoints")
    (setq cl (getvar 'clayer))
  (setvar 'clayer swllayer)

      ;; --------------------------- START ROUTINE --------------------------- ;;
 (if
(and
    (if (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (getvar 'clayer))))))
(alert "\nPlease unlock the current layer before proceeding!")
T
)
    (setq pt1 (getpoint "\nSelect high grade point: "))
    (and
(setq elv1 (car (entsel "\nSelect high grade elevation text: ")))
(if (null (wcmatch (cdr (assoc 0 (entget elv1))) "TEXT,MTEXT"))
    (null (princ "\nObject is not a text"))
    T)
)
    (setq pt2 (getpoint "\nSelect low grade point: "))
    (and
(setq elv2 (car (entsel "\nSelect low grade elevation text: ")))
(if (null (wcmatch (cdr (assoc 0 (entget elv2))) "TEXT,MTEXT"))
    (null (princ "\nObject is not a text"))
    T)

(setq tmpln
     (entmakex
(list
     '(0 . "LINE")
     (cons 10 pt1)
     (cons 11 pt2)
     )
)

BIGAL

  • Swamp Rat
  • Posts: 1032
  • 40 + years of using Autocad
Ok a simple method and it takes a few goes to get used to it, if you go from pt1 to pt2 the right is always just that pt1->pt2->right.

So if pick 2 points bottom then up on screen its right, if pick top then go down it will look like you want to go left. You do get used to it very quick.

You just take (angle pt1 pt2) and add (/ pi 2.0) for angle direction.

I will let you make code, if get stuck post again.

Just try it  picking 2 points.
A man who never made a mistake never made anything

Strydaris

  • Mosquito
  • Posts: 4
Hi Bigal,

I did think of using this and forcing the user to use a certain direction when picking the points. Most of the time when doing this work the ucs will be adjusted so that the orientation is how it's shown in the image.

Problem being is that the numbers are going to vary and the calcs I need to do afterwards require them to be in a certain order. I suppose I could write an if statement saying if el1 is greater than el2 than start from pt1 else start from pt2.

BIGAL

  • Swamp Rat
  • Posts: 1032
  • 40 + years of using Autocad
In another scenario "is text readable" so in your case look at the angle between the 2 points then you can set a min max value if in range ok if not swap the points around as you suggested.

Code: [Select]
(setq temp pt1)
    (setq pt1 pt2)
    (setq pt2 temp)

A man who never made a mistake never made anything