PDA

View Full Version : scale position of notes


ccowgill
2005-10-08, 01:13 AM
I am looking for a routine that fixes a problem I am having.

I have a bunch of notes in paperspace that point to Items in a viewport, the viewport needs the scale to change from 1/40 to 1/20 and I would like to change the location of the notes based on scaling from the center of the viewport (in theory it would put the arrowheads in their original locations, but keep all text the same size) Any suggestions?

Opie
2005-10-08, 04:00 AM
That is a complex request. Are the current arrowheads classified as a leader entity? You may want to select all of the arrowheads and the viewport in your routine. And then calculate the new location of the beginning of each leader's arrowhead for the different scale.

CAB2k
2005-10-08, 02:14 PM
Something like this?

pseudo code

get center of vp in paper space
calc move amount (/ (/ 1 40) (/ 1 20)) = sc
Select text & leaders & more
Step through ss
.. cond
.... mtext or leader attached
..... get attached item
..... get leader arrow point = p1
..... move mtext & leader
...... (polar center (angle center p1) (* (distance center p1) (1+ sc))
..... remove items from ss

.... else
..... move item (p1 = insert point)
...... (polar center (angle center p1) (* (distance center p1) (1+ sc))
..... remove items from ss


Well something like that, see ya Monday

CAB2k
2005-10-09, 05:58 AM
Here is a very basic lisp with no error checking.
You must pick the center of the viewport.

Here are some improvements that are needed:
make sure you are in paper space
Select viewport & calc center point
Check vp scale & set to new scale
Calc the scale factor, hard coded at 2.0 now
Check text & leader layer to see if locked.
Check Leader text to see if more that one leader attached.


;; move text & leaders from center point using vector
;; and scale factor
(defun c:move_text (/ vpscalefactor)
(command "UNDO" "Begin")
(setq usercmd (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq useros (getvar "osmode"))

(setq vpscalefactor 2.0) ; (/ (/ 1 20.0) (/ 1 40.0))
(prompt "\nSelect Text.")
(if (and
(setq ss (ssget (list '(0 . "TEXT,MTEXT,LEADER"))))
(setq pc (getpoint "\nSelect center of view port."))
)
(progn
(while (> (sslength ss) 0)
(setq ent (ssname ss 0)
esub nil
)
(setq elst (entget ent))
(setq p1 (cdr (assoc 10 elst))) ; get point
(ssdel ent ss) ; remove from selection set
(cond

((= (cdr (assoc 0 elst)) "LEADER")

(and (setq esub (cdr (assoc 340 elst))) ; has mtext
(setq elst (entget esub))
(ssdel esub ss)
)
)

((= (cdr (assoc 0 elst)) "MTEXT")
;; check for attached leader
(setq idx (length elst))
(while (> (setq idx (1- idx)) -1)
(setq lst (nth idx elst))
(cond ; find LEADER if it exist
;; TEXT may have many 330 codes so test each one
((and (= (car lst) 330) ; pointer to leader
(setq sublst (entget (cdr lst))) ; valid ent ??
(= (cdr (assoc 0 sublst)) "LEADER")
) ; founs it
(setq esub (cdr (assoc -1 sublst))) ; leader name
(ssdel esub ss) ; note, may not be in selection set
(setq p1 (cdr (assoc 10 sublst))) ; point of arrow
(setq idx 0) ; 0 = exit loop
) ; cond
) ; cond stmt
) ; while
)
) ; end condstmt

(setq dist (distance pc p1)
ang (angle pc p1)
newpt (polar pc ang (* dist vpscalefactor))
)
(setvar "osmode" 0)
(if esub ; move both
(command "._move" ent esub "" p1 newpt)
(command "._move" ent "" p1 newpt)
)
)
)
)
(setvar "CMDECHO" usercmd)
(setvar "osmode" useros)
(command "UNDO" "End")
(princ)
)

ccowgill
2005-10-10, 11:19 AM
I haven't quite tried any solutions yet, I figured I should try to make sure I was clear on what I am looking for. It isn't really a scale, it is a displacement. We use a third party software Eagle Point, and it has the ability to scale nodes (points) it gives you three options with the pt descrip, elev, and number, you can scale them with it, leave them alone, or displace them, with the last option, I know AutoCAD is capable to displace objects.

ccowgill
2005-10-10, 11:26 AM
That is a complex request. Are the current arrowheads classified as a leader entity? You may want to select all of the arrowheads and the viewport in your routine. And then calculate the new location of the beginning of each leader's arrowhead for the different scale.

I am using leaders with the text attached. I tried the code that was posted by ab2draft and successfully created a power exit twice when tried. Is there a way to get it to allow selection of dimensions that are over the viewport, I would suppose those could be scaled separately, but we use dimensions for our property owner info (boss wanted a self expanding box, and that was the best I could come up with)

CAB2k
2005-10-10, 02:06 PM
I am using leaders with the text attached. I tried the code that was posted by ab2draft and successfully created a power exit twice when tried.

I'm still half asleep, so please explain 'Power Exit' as I'm not familiar with the
term. And did the routine do what you wanted with the text & leaders?

Wanderer
2005-10-10, 02:08 PM
I'm still half asleep, so please explain 'Power Exit' as I'm not familiar with the
term. And did the routine do what you wanted with the text & leaders?hmm, my impression while reading that was power exit = crash? just a guess though...

CAB2k
2005-10-10, 02:28 PM
Well that could be as there is little error checking.
But it won't proceed without a selection set & a center point so
I'm at a loss without more information.

PS if power exit = crash the he said he "successfully crashed" ?

Wanderer
2005-10-10, 02:44 PM
Well that could be as there is little error checking.
But it won't proceed without a selection set & a center point so
I'm at a loss without more information.

PS if power exit = crash the he said he "successfully crashed" ?ps... don't know... ~looks around~ autoLISP forum? how'd I get in here? ~slinks out~

ccowgill
2005-10-10, 03:17 PM
Power Exit - Verb, AutoCAD exits with out warning, no error messages, no ask to save, no nothing, just exits.

In the general forum, there are a few threads, and one suggested there is no way to recreate the crash succesfully, this lisp routine in it's current state seems to do so.

Before the crash, I got all the way to the end. it had just finished repositioning the leaders and such and AutoCAD Power-Exited.

Opie
2005-10-10, 03:19 PM
Power Exit - Verb, AutoCAD exits with out warning, no error messages, no ask to save, no nothing, just exits.

In the general forum, there are a few threads, and one suggested there is no way to recreate the crash succesfully, this lisp routine in it's current state seems to do so.

Before the crash, I got all the way to the end. it had just finished repositioning the leaders and such and AutoCAD Power-Exited.
It may be an EP issue. I have had that problem a few times myself with other lisp routines working in EP.

CAB2k
2005-10-10, 03:36 PM
Thanks for the clarification.

Melanie you were quite correct. Sorry if my post came across short, it was not intended.

There is nothing going on the this simple lisp that I see would cause a problem.
Perhaps you should audit the drawing & fix any problems. I have had leaders that
were detached improperly and caused problem when they were moved because the
attached object did not exist.

If that doesn't do it, post the drawing here & someone will take a look at it.
I just have plain ACAd 200 & 2004 but I'll see it there is a problem there.

Opie
2005-10-10, 03:39 PM
Thanks for the clarification.

Melanie you were quite correct. Sorry if my post came across short, it was not intended.

There is nothing going on the this simple lisp that I see would cause a problem.
Perhaps you should audit the drawing & fix any problems. I have had leaders that
were detached improperly and caused problem when they were moved because the
attached object did not exist.

If that doesn't do it, post the drawing here & someone will take a look at it.
I just have plain ACAd 200 & 2004 but I'll see it there is a problem there.
He may have a corrupt dwg, but I think it may be EP more so. EP places entities in the dwg and knows where all of those entities are placed. If you move or change those entities, and EP doesn't keep up, it seems to crash. (That is just my observation).

ccowgill
2005-10-10, 03:50 PM
That could be possible, but unlikely, the particular drawing I have has no references other than the base drawing to EP information. the drawing has been audited and checked for errors, none were found, I'm using 2005 but I'll post the drawing to see if anyone can come up with any suggestions.

I have already completed the changes in this drawing manually, but I would suppose the routine should work both directions.

Wanderer
2005-10-10, 04:02 PM
Thanks for the clarification.

Melanie you were quite correct. Sorry if my post came across short, it was not intended.
WooHoo! I was right about something. :Puffy:
don't worry, you didn't come across as short at all, I just like to use my ignorance as an excuse... erm, well, to not know things. ;)

Opie
2005-10-10, 04:23 PM
WooHoo! I was right about something. :Puffy:
don't worry, you didn't come across as short at all, I just like to use my ignorance as an excuse... erm, well, to not know things. ;)
Are you sure that's an excuse? ;)

CAB2k
2005-10-10, 09:39 PM
Found the culprit. It was a leader with this (340 . <Entity name: 0>) an ename that
doesn't exist. Here is the revised code.


;; move text & leaders from center point using vector
;; and scale factor
(defun c:move_text (/ vpscalefactor)
(command "UNDO" "Begin")
(setq usercmd (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq useros (getvar "osmode"))

(setq vpscalefactor 2.0) ; (/ (/ 1 20.0) (/ 1 40.0))
(prompt "\nSelect Text.")
(if (and
(setq ss (ssget (list '(0 . "TEXT,MTEXT,LEADER"))))
(setq pc (getpoint "\nSelect center."))
)
(progn
(while (> (sslength ss) 0)
(setq ent (ssname ss 0)
esub nil
)
(setq elst (entget ent))
(setq p1 (cdr (assoc 10 elst))) ; get point
(ssdel ent ss) ; remove from selection set
(cond

((= (cdr (assoc 0 elst)) "LEADER")
(setq esub (cdr (assoc 340 elst))) ; has mtext
(if (setq elst (entget esub))
(ssdel esub ss)
(setq esub nil) ; bad ename
)
)

((= (cdr (assoc 0 elst)) "MTEXT")
;; check for attached leader
(setq idx (length elst))
(while (> (setq idx (1- idx)) -1)
(setq lst (nth idx elst))
(cond ; find LEADER if it exist
;; TEXT may have many 330 codes so test each one
((and (= (car lst) 330) ; pointer to leader
(setq sublst (entget (cdr lst))) ; valid ent ??
(= (cdr (assoc 0 sublst)) "LEADER")
) ; founs it
(setq esub (cdr (assoc -1 sublst))) ; leader name
(ssdel esub ss) ; note, may not be in selection set
(setq p1 (cdr (assoc 10 sublst))) ; point of arrow
(setq idx 0) ; 0 = exit loop
) ; cond
) ; cond stmt
) ; while
)
) ; end condstmt

(setq dist (distance pc p1)
ang (angle pc p1)
newpt (polar pc ang (* dist vpscalefactor))
)
(setvar "osmode" 0)
(if esub ; move both
(command "._move" ent esub "" p1 newpt)
(command "._move" ent "" p1 newpt)
)
)
)
)
(setvar "CMDECHO" usercmd)
(setvar "osmode" useros)
(command "UNDO" "End")
(princ)
)

ccowgill
2005-10-10, 09:51 PM
It seems to work well, it has a small issue with leaders and mtext that arnt attached though. I'm quite busy right now, I will try to tweek it a little, to add poly lines to the selection set

LRaiz
2005-10-10, 09:58 PM
I realize that my comment is off topic and I really don't want to offend anyone by using an R word. I just want to inform those who are interested that in Revit the requested functionality is supported without any need for programming. When user changes view scale Revit automatically adjusts everything in such a way that geometry is scaled appropriately but annotations including text notes and dimension text stay the same size on printed documents. Note leaders automatically point to scaled geometry, no programming necessary.

I am not suggesting that everyone should rush switching to Revit. First of all Revit is strong for building design but is not engineered for other applications (e.g. civil). Secondly your firm may have internal reasons that force it to stick with ADT or Autocad. I just wanted to point out that Revit does address the need to have text notes with enough intelligence to handle view scale changes automatically.

CAB2k
2005-10-10, 10:01 PM
The issue being that they do not maintain the distance from each other. That is to be expected as
the unattached leader and mtext are treated as separate objects. If they are not attached they are
separate objects. There is no way to tell if the leader and mtext are to moved together short of
having the user pick the two.
Adding other objects may result in the same issue if there is no way associate the plines with
the text it is supposed to be moved with.

Good luck with your project.

ccowgill
2005-10-10, 10:11 PM
I appreciate your help, it is a great start, it will hopefully help me to learn quite a lot about Lisp programming.