Author Topic: grread + ortho  (Read 9946 times)

0 Members and 2 Guests are viewing this topic.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
grread + ortho
« on: February 11, 2009, 12:41:15 PM »
I am in the process of playing around with some code that asks for 2 points (StartPoint EndPoint) then runs through a grread loop till a third point is picked.

While running through the loop the code creates 2 arc, one from the StartPoint to the CursorPoint and one from the EndPoint to the CursorPoint.  So my question is:  How do I get some sort of ortho between the StartPoint and EndPoint while in the grread loop.

any code would be greatly appreciated.  I am having a BF on this issue.

Thanks
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

T.Willey

  • Needs a day job
  • Posts: 5251
Re: grread + ortho
« Reply #1 on: February 11, 2009, 12:58:07 PM »
Code: [Select]
(progn
    (setq pt1 (getpoint "\n Select first point: "))
    (while (not (member (car (setq tempList (grread T 0))) '(11 25)))
        (redraw)
        (if (equal (car tempList) 5)
            (progn
                (setq pt2 (cadr tempList))
                (if (> (abs (- (car pt1) (car pt2))) (abs (- (cadr pt1) (cadr pt2))))
                    (setq pt3 (list (car pt2) (cadr pt1) (caddr pt2)))
                    (setq pt3 (list (car pt1) (cadr pt2) (caddr pt2)))
                )
                (grdraw pt1 pt3 1)
            )
        )
    )
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

dustinthiesse

  • Guest
Re: grread + ortho
« Reply #2 on: February 11, 2009, 01:09:03 PM »
Along the same lines here, is there any way to be able to snap to objects while using grread?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: grread + ortho
« Reply #3 on: February 11, 2009, 01:11:35 PM »
Along the same lines here, is there any way to be able to snap to objects while using grread?

Take a look here for my version of snaps while using grread:

http://www.theswamp.org/index.php?topic=25575.msg307823#msg307823

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: grread + ortho
« Reply #4 on: February 11, 2009, 01:16:35 PM »
Thanks Tim

So what if Im creating this on an angle and I want to respect that angle as my ortho?
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

T.Willey

  • Needs a day job
  • Posts: 5251
Re: grread + ortho
« Reply #5 on: February 11, 2009, 01:25:57 PM »
Thanks Tim

So what if Im creating this on an angle and I want to respect that angle as my ortho?

Then you are going to have to do some math.   :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: grread + ortho
« Reply #6 on: February 11, 2009, 01:28:35 PM »
That was I quess my original question (although it didn't read that way  ;-) )

What would that math look like..... :lol:
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

T.Willey

  • Needs a day job
  • Posts: 5251
Re: grread + ortho
« Reply #7 on: February 11, 2009, 01:48:19 PM »
Here you go.  My logic ( if you can't follow the code, or just to make it easier ) is to get the angle you want to snap to.  Then I get all four of the angles.  Then as you drag the mouse, then current angle is gotten.  Then that is compared to the angles in the list ( the four angles ).  When it finds the closes one, it uses that angle to snap to.  The distance is the total distance from the start point to the drag point.  Not sure if that is correct, but that is my simple thinking.  It seems this could be a sub if you want it to be, and could be coded a little different, but you can get the picture from it.

Code: [Select]
(progn
    (setq ang1 (getangle "\n Enter angle to snap ortho to: "))
    (setq ang2 (rem (+ ang1 (* pi 0.5)) (* pi 2.)))
    (setq ang3 (rem (+ ang1 pi) (* pi 2.)))
    (setq ang4 (rem (+ ang1 (* pi 1.5)) (* pi 2.)))
   
    (setq pt1 (getpoint "\n Select first point: "))
    (while (not (member (car (setq tempList (grread T 0))) '(11 25)))
        (redraw)
        (if (equal (car tempList) 5)
            (progn
                (setq pt2 (cadr tempList))
                (setq ang (angle pt1 pt2))
                (setq dist (distance pt1 pt2))
                (setq pt3
                    (polar
                        pt1
                        (caar
                            (vl-sort
                                (mapcar
                                    '(lambda (x)
                                        (cons x (abs (- x ang)))
                                    )
                                    (list ang1 ang2 ang3 ang4)
                                )
                                '(lambda (a b)
                                    (< (cdr a) (cdr b))
                                )
                            )
                        )
                        dist
                    )
                )
                (grdraw pt1 pt3 1)
            )
        )
    )
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: grread + ortho
« Reply #8 on: February 11, 2009, 01:55:33 PM »
The distance is the total distance from the start point to the drag point

That was my initial reaction to my code,  Probably not correct but will it be sufficient??

<cousin Eddie>
Idunno
</cousin Eddie>

BTW  Sorry I didn't post the code but right now it uses numerous lisps to create objects and I didn't feel like finding them all and posting just for this.  Maybe when it is finished.

Here is a pic of what I am attempting to accomplish:
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

T.Willey

  • Needs a day job
  • Posts: 5251
Re: grread + ortho
« Reply #9 on: February 11, 2009, 02:02:29 PM »
A simple thing would be to change the ' snapang ' variable, and turn ortho on.

I'm not sure what you are looking to do from the pic.  Sorry.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: grread + ortho
« Reply #10 on: February 11, 2009, 02:10:47 PM »
Sorry 'bout that  :ugly:

I am drawing the bubble with the arced leaders on each side.

So the program prompts for the ID then prompts for the begin and end points then it begins the loop,  It creates the bubble, text and leaders which dynamically change with the cursor position until a point is pick (for the bubble and text)

Thats the jist of it.  I will hopefully be including some code that if the user goes beyond the begining and ending point then the double leaders change to a single, we'll see.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

T.Willey

  • Needs a day job
  • Posts: 5251
Re: grread + ortho
« Reply #11 on: February 11, 2009, 02:39:14 PM »
Okay so I think I might be getting it now.   :-D

You pick the start point, then you pick the next point ( at an angle ).  You continue along theses lines until enter is pressed.  When do you insert the block?  Do you pick from left to right ( doesn't really matter which direction ) one leader at a time?  Or the whole length and then you divide the distance ( or something ) to get the leader points?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: grread + ortho
« Reply #12 on: February 11, 2009, 02:48:24 PM »
Okay so I think I might be getting it now.   :-D

You pick the start point, then you pick the next point (this is the endpoint (las tpoint)) ( at an angle ).  You continue along theses lines until enter is pressed. No just those 2 points  When do you insert the block? After the last point is defined the block is created and follows the cursor until it it "dropped"  Do you pick from left to right ( doesn't really matter which direction ) one leader at a time?  Or the whole length and then you divide the distance YES ( or something ) to get the leader points?

Coming into focus......
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: grread + ortho
« Reply #13 on: February 11, 2009, 02:51:51 PM »
Here is the code without the sub lisps:
Code: [Select]
(defun C:FOO (/ TrussID StartPoint EndPoint CursorPos Cursor MTextData Bubble Arc1Data Arc2Data Arc1Prop Arc2Prop
VL-Bubble VL-Arc1Data VL-Arc2Data Int1 Int2 OldOrthomode)

; Turn on orthomode
(setq OldOrthomode (getvar "ORTHOMODE"))
(setvar "ORTHOMODE" 1)
;; Create needed layer
(STDLIB_LAYER_ADD "A-FRAM-ANNO" nil)
;; Create needed Textstyle
(STDLIB_TEXTSTYLE_CREATE "Archquik" 0.09375 "Archquik" nil)
;; Get truss ID number/letter
(if (not (setq TrussID (strcase (getstring "\n Enter truss identifier: <A>"))))
(setq TrussID "A")
)
(alert Trussid)
;; Get creation points and angles
(setq StartPoint (getpoint "\n Define start point for callout: "))
(setq EndPoint (getpoint StartPoint "\n Define end point for callout: "))
;; Get Cursor position
(while (= (car (setq CursorPos (grread T 5 0))) 5)
;; get coordinates from grread
(setq Cursor (list (nth 0 (cadr CursorPos)) (nth 1 StartPoint) 0))
;; Delete the old info
(if MTextData
(progn
(entdel Bubble)
(entdel MTextData)
(entdel Arc1Data)
(entdel Arc2Data)
)
)
;; Create Bubble
;; *STDLIB_MAKECIRC <CENTERPOINT> <RADIUS> <LAYER> <LINETYPE>
(setq Bubble (STDLIB_MAKECIRC Cursor 6.0 "A-FRAM-ANNO" "Continuous"))
;; Create mtext data
;; *STDLIB_MAKETEXT <TEXT> <INSPOINT> <LAYER> <STYLE> <ATTACHPT> <DIRECTION>
(setq MTextData (STDLIB_MAKETEXT TrussID Cursor 4.5 "A-FRAM-ANNO" "Archquik" 5 1))
;; Get arc 1 properties
(setq Arc1Prop (ARC_PROP StartPoint Cursor 6.0))
(setq Arc2Prop (ARC_PROP EndPoint Cursor 6.0))
;; Create arc legs
;;*STDLIB_MAKEARC <CENTERPOINT> <RADIUS> <LAYER> <LINETYPE> <COLOR> <STARTANGLE> <ENDANGLE>
(setq Arc1Data (STDLIB_MAKEARC (nth 0 Arc1Prop)(nth 1 Arc1Prop) "A-FRAM-ANNO" "Continuous" 256 (nth 2 Arc1Prop)(nth 3 Arc1Prop)))
(setq Arc2Data (STDLIB_MAKEARC (nth 0 Arc2Prop)(nth 1 Arc2Prop) "A-FRAM-ANNO" "Continuous" 256 (nth 2 Arc2Prop)(nth 3 Arc2Prop)))
)
;; Change endpoints to intersect bubble
;; Get vl-obj names from enames
(setq VL-Bubble (vlax-ename->vla-object Bubble))
(setq VL-Arc1Data (vlax-ename->vla-object Arc1Data))
(setq VL-Arc2Data (vlax-ename->vla-object Arc2Data))
;; Get intersection points
(setq Int1 (vlax-invoke VL-Bubble 'intersectwith VL-Arc1Data acExtendNone))
(setq Int2 (vlax-invoke VL-Bubble 'intersectwith VL-Arc2Data acExtendNone))
;; Change endpoints of arcs
(vlax-put VL-Arc1Data 'StartAngle (angle (vlax-get VL-Arc1Data 'Center) Int1))
(vlax-put VL-Arc2Data 'StartAngle (angle (vlax-get VL-Arc2Data 'Center) Int2))
)
;; SUB TO GET PROPERTIES TO CREATE AN ARC BASED ON CHORD LENGTH AND RAY LENGTH
;; <STARTPOINT> <ENDPOINT> <RAYLENGTH>
(defun ARC_PROP (SP EP Ray / BaseAngle ChordLength MidPoint RayPoint ArcRadius ArcCenter StartAngle EndAngle)

(setq BaseAngle (angle SP EP))
(setq ChordLength (distance SP EP))
(setq MidPoint (polar SP (angle SP EP) (/ ChordLength 2.0)))
(setq RayPoint (polar MidPoint (+ (DTR 90.0) BaseAngle) Ray))
(setq ArcRadius (/ (+ (* 4.0 (* Ray Ray))(* ChordLength ChordLength))(* 8.0 Ray)))
(setq ArcCenter (polar RayPoint (+ (DTR 270.0) BaseAngle) ArcRadius))
(setq StartAngle (angle ArcCenter EP))
(setq EndAngle (angle ArcCenter SP))
(list ArcCenter ArcRadius StartAngle EndAngle)
)
(princ)

Maybe this will help ???
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

T.Willey

  • Needs a day job
  • Posts: 5251
Re: grread + ortho
« Reply #14 on: February 11, 2009, 03:24:29 PM »
I'll study it a little more when I come back from lunch, as time allows.   :wink:

A quick note
Code: [Select]
(if (not (setq TrussID (strcase (getstring "\n Enter truss identifier: <A>"))))
(setq TrussID "A")
)
This will never put the default as ' A '.  ' getstring ' will never return nil.  If enter is pressed, it returns an empty string ' "" ', so test to see ' TrussID ' equals that, and if so then default to ' A '.

The distance is the total distance from the start point to the drag point

That was my initial reaction to my code,  Probably not correct but will it be sufficient??

No, and here is the new code that will show it correctly, as a real sub.

Code: [Select]
(defun GetPointAtAngle ( pt baseAng / tempList pt2 flag ang pt3 tempAng )
   
    (setq flag T)
    (while
        (and
            flag
            (not (member (car (setq tempList (grread T 0))) '(11 25)))
        )
        (redraw)
        (if (member (car tempList) '(3 5))
            (progn
                (setq pt2 (cadr tempList))
                (setq ang (angle pt pt2))
                (setq tempAng
                    (caar
                        (vl-sort
                            (mapcar
                                '(lambda (x)
                                    (cons x (abs (- x ang)))
                                )
                                (list
                                    baseAng
                                    (rem (+ baseAng (* pi 0.5)) (* pi 2.))
                                    (rem (+ baseAng pi) (* pi 2.))
                                    (rem (+ baseAng (* pi 1.5)) (* pi 2.))
                                )
                            )
                            '(lambda (a b)
                                (< (cdr a) (cdr b))
                            )
                        )
                    )
                )
                (setq pt3
                    (polar
                        pt
                        tempAng
                        (*
                            (cos
                                (if (> tempAng ang)
                                    (- tempAng ang)
                                    (- ang tempAng)
                                )
                            )
                            (distance pt pt2)
                        )
                    )
                )
                (grdraw pt pt3 1)
                (if (equal (car tempList) 3)
                    (setq flag nil)
                    (setq pt3 nil)
                )
            )
        )
    )
    (redraw)
    pt3
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: grread + ortho
« Reply #15 on: February 11, 2009, 03:31:28 PM »

A quick note
Code: [Select]
(if (not (setq TrussID (strcase (getstring "\n Enter truss identifier: <A>"))))
(setq TrussID "A")
)
This will never put the default as ' A '.  ' getstring ' will never return nil.  If enter is pressed, it returns an empty string ' "" ', so test to see ' TrussID ' equals that, and if so then default to ' A '.


Yeah I saw that, Yet I was more worried about getting everything else to work first,  It need to check for "" instead.

Thanks for the catch, I'll give this a go.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

T.Willey

  • Needs a day job
  • Posts: 5251
Re: grread + ortho
« Reply #16 on: February 11, 2009, 06:06:34 PM »
So do you still need help?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: grread + ortho
« Reply #17 on: February 11, 2009, 07:54:38 PM »
So do you still need help?

Let me look at it and get back to you in the morning...

Thanks TIM
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: grread + ortho
« Reply #18 on: February 12, 2009, 03:06:27 PM »
Thanks Tim,

I got it working as hoped.  Still scratching my head at the code though (maybe some commenting  :wink: )

I am in the process of dissecting it now

Thanks again
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

T.Willey

  • Needs a day job
  • Posts: 5251
Re: grread + ortho
« Reply #19 on: February 12, 2009, 05:26:43 PM »
Thanks Tim,

I got it working as hoped.  Still scratching my head at the code though (maybe some commenting  :wink: )

I am in the process of dissecting it now

Thanks again

Sounds good.  You're welcome Tim.  Here is the code commented a bit to help you understand it.  Let me know if there is still a section you don't understand.

Code: [Select]
(defun GetPointAtAngle ( pt baseAng / tempList pt2 flag ang pt3 tempAng )
   
    (setq flag T)
    (while
        (and
            flag
            (not (member (car (setq tempList (grread T 0))) '(11 25)))
        )
        ; above just lets you move the mouse until an enter is hit, by right click or not
        (redraw)
        ; just to get the old graphic line off the screen
        (if (member (car tempList) '(3 5))
        ; if the mouse is moved, or left clicked do what is below
            (progn
                (setq pt2 (cadr tempList))
                ; get the point of the mouse
                (setq ang (angle pt pt2))
                ; get the angle between the supplied point, and where the mouse is
                (setq tempAng
                    (caar
                        (vl-sort
                            (mapcar
                                '(lambda (x)
                                    (cons x (abs (- x ang)))
                                )
                                ; make a list of lists, ( the 90 degree angle list . the amount of difference between that angle, and the on one between the supplied point, and the mouse )
                                ; this will be used to see what angle the mouse is closest to, so that we can show the correct angle being snaped to.
                                (list
                                    baseAng
                                    (rem (+ baseAng (* pi 0.5)) (* pi 2.))
                                    (rem (+ baseAng pi) (* pi 2.))
                                    (rem (+ baseAng (* pi 1.5)) (* pi 2.))
                                )
                                ; make a list of all the angles off the supplied angle, 90 degree list
                            )
                            '(lambda (a b)
                                (< (cdr a) (cdr b))
                            )
                            ; sort the list by the smallest angle
                        )
                    )
                )
                ; set the correct 90 degree angle
                (setq pt3
                    (polar
                        pt
                        tempAng
                        (*
                            (cos
                                (if (> tempAng ang)
                                    (- tempAng ang)
                                    (- ang tempAng)
                                )
                                ; to find the correct angle for the trig function, we have to find the angle that is the difference of the angle of points, and the angle of 90 degrees
                                ; since we need it to be positive, and in the right direction, we have to subtract the smaller angle from the larger one.
                            )
                            (distance pt pt2)
                            ; this is the hypothnus
                        )
                        ; getting the correct distance takes a trig function.  since we know the angle and the hypothnus, then we can figure out the adjacent distance.
                    )
                )
                (grdraw pt pt3 1)
                (if (equal (car tempList) 3)
                    (setq flag nil)
                    (setq pt3 nil)
                )
                ; if the point is picked, and not just draged about, then set flag to nil to end the while
            )
        )
    )
    (redraw)
    pt3
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Maverick®

  • Seagull
  • Posts: 14778
Re: grread + ortho
« Reply #20 on: February 12, 2009, 05:35:57 PM »
Wait.  Which one is TIM and which is Tim?  :-D

FengK

  • Guest
Re: grread + ortho
« Reply #21 on: March 08, 2009, 03:54:03 AM »
Code: [Select]
            (not (member (car (setq tempList (grread T 0))) '(11 25)))

Tim, according to the autolisp reference, seems the the 1st element of grread function's return values is 2, through 12. How did you get the 25? Thanks.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: grread + ortho
« Reply #22 on: March 08, 2009, 06:48:42 AM »
Hi xycadd,

Try enter (grread) at command line, then right click. It returns 11 or 25 according to SHORTCUTMENU sysvar value.
Speaking English as a French Frog

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: grread + ortho
« Reply #23 on: March 09, 2009, 07:20:06 AM »
OK here is the semi-final results of your help.  This is what I was shooting for.  This has been approved for use at my company.

A bit more tweaking and it'l be totally ready to go.

Thanks again TIM
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: grread + ortho
« Reply #24 on: March 09, 2009, 08:46:50 AM »
Hi,

You can see here a way to use (and toogle) orthomode inside a grread loop.
Speaking English as a French Frog

T.Willey

  • Needs a day job
  • Posts: 5251
Re: grread + ortho
« Reply #25 on: March 09, 2009, 11:14:18 AM »
OK here is the semi-final results of your help.  This is what I was shooting for.  This has been approved for use at my company.

A bit more tweaking and it'l be totally ready to go.

Thanks again TIM

You're welcome Tim.  Glad you got it going.

Code: [Select]
            (not (member (car (setq tempList (grread T 0))) '(11 25)))

Tim, according to the autolisp reference, seems the the 1st element of grread function's return values is 2, through 12. How did you get the 25? Thanks.

Hi xycadd,

Try enter (grread) at command line, then right click. It returns 11 or 25 according to SHORTCUTMENU sysvar value.

Exactly.  Thanks gile.  Found that out when I was developing the polyline arrow routine I did.  Alan and I had ours setup differently, so it wasn't working correctly for him, and that was the reason why, so I keep that store in my memory back.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

FengK

  • Guest
Re: grread + ortho
« Reply #26 on: March 10, 2009, 04:52:35 AM »
Hi xycadd,

Try enter (grread) at command line, then right click. It returns 11 or 25 according to SHORTCUTMENU sysvar value.

Thanks gile!