Author Topic: grread + ortho  (Read 9933 times)

0 Members and 1 Guest 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: 7527
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.