TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jonesy on March 29, 2005, 03:48:30 AM

Title: Scale a block relative to viewport
Post by: jonesy on March 29, 2005, 03:48:30 AM
I am trying to ensure certain blocks are always the same plotted size, no-matter what the scale of the viewport is.

We use north arrows on virtually every drawing, and each user has their own idea of the size it should be.

What I would like is

To be able to "grab" the viewport scale.
To insert the north arrow at say 5% of the frame size (I think)
Allow the user to position the north arrow at a suitable location.

Any help would be much appreciated.

Many thanks
Title: Scale a block relative to viewport
Post by: hudster on March 29, 2005, 04:43:53 AM
I do something similar, but I user the userr1 variable, so on the custom menus I wrote I have a setup an option with a line containing the following

Code: [Select]
[1: 100]^C^C_setvar userr1 100

I then insert the blocks setting the scale as per the userr1 value, as per this code.

Code: [Select]
[62(P002,Switched Socket)]^c^c(setq old (getvar "clayer"))$M=$(if,$(=,$(getvar,tilemode),0),_pspace,_r) _attdia 1 _-layer _t;_62_SM_POW;_m _62_SM_POW;_c BLUE _62_SM_POW;;_-insert "P002" _xscale $(if,$(=,$(getvar,tilemode),0),1,$(getvar,userr1)) _yscale $(if,$(=,$(getvar,tilemode),0),1,$(getvar,userr1)) _zscale $(if,$(=,$(getvar,tilemode),0),1,$(getvar,userr1)) \\_-layer _s !old;;
Title: Scale a block relative to viewport
Post by: CADaver on March 29, 2005, 07:46:13 AM
Shhhh...
Place ALL annotation, including North arrows in PS at a scale of 1
Title: Scale a block relative to viewport
Post by: MP on March 29, 2005, 07:54:12 AM
:lol:
Title: Scale a block relative to viewport
Post by: daron on March 29, 2005, 07:56:21 AM
Of course, that may not be an option.
Title: Scale a block relative to viewport
Post by: jonesy on March 29, 2005, 11:30:26 AM
Quote from: CADaver
Shhhh...
Place ALL annotation, including North arrows in PS at a scale of 1

No can do I'm afraid. North Arrows must be in the model. Usually the jobs have many viewports, usually rotated (with differant rotations) so the road is horizontal to the page. It would be difficult for the part-time cad users to figure out which way is north, then rotate the arrow to the correct alignment. North would always be up no matter how the viewport had been rotated :lol:
Title: Scale a block relative to viewport
Post by: CADaver on March 29, 2005, 03:21:36 PM
Quote from: jonesy
No can do I'm afraid. North Arrows must be in the model. Usually the jobs have many viewports, usually rotated (with differant rotations) so the road is horizontal to the page. It would be difficult for the part-time cad users to figure out which way is north, then rotate the arrow to the correct alignment. North would always be up no matter how the viewport had been rotated :lol:


??? ... ummm... drafters don't know which way North is??  But they're gonna work with rotated viewports???

???

okay.
Title: Scale a block relative to viewport
Post by: David Hall on March 29, 2005, 04:08:29 PM
Quote from: CADaver
??? ... ummm... drafters don't know which way North is??  But they're gonna work with rotated viewports???

???

okay.


Believe me it happens
Title: Scale a block relative to viewport
Post by: David Hall on March 29, 2005, 04:10:54 PM
[psuedo code]  Do we know what viewport we are in?  if so, can we pull the scale value from that?
Title: Scale a block relative to viewport
Post by: jonesy on March 30, 2005, 03:10:27 AM
Quote from: CADaver
Quote from: jonesy
No can do I'm afraid. North Arrows must be in the model. Usually the jobs have many viewports, usually rotated (with differant rotations) so the road is horizontal to the page. It would be difficult for the part-time cad users to figure out which way is north, then rotate the arrow to the correct alignment. North would always be up no matter how the viewport had been rotated :lol:


??? ... ummm... drafters don't know which way North is??  But they're gonna work with rotated viewports???

???

okay.


No, not the full-time cad user/drafters... The engineers who dont know how to read a base map! (Some of them rotate the bloody thing in model space to get the map to line up with the survey they have had done, and then cant figure out where North is. arggh :x  :x  :x I wish they would leave things alone. The times I have asked them to get the surveys done to the National Grid, then nothing needs to be moved or rotated in the model, but what do I know, I am only the Cad Monkey!
Title: Scale a block relative to viewport
Post by: CADaver on March 30, 2005, 08:03:53 AM
Quote from: jonesy
The engineers who dont know how to read a base map! (Some of them rotate the bloody thing in model space to get the map to line up with the survey they have had done, and then cant figure out where North is. arggh :x  :x  :x
Then that has nothing to do with paperspace annotation. Cuz' if a guy doesn't know which way is North, a rotated viewport will fry him.  And an Auto-Inserting North Arrow is noodled if the base map has been rotated.  It seems there are other issues here that need to be resolved before embarking on such an auto-Insertion function.
Title: Scale a block relative to viewport
Post by: jonesy on March 30, 2005, 08:20:16 AM
OK Mr Cadaver, I'll agree with you :D

Our company standards are to annotate in model. This is made easier than it sounds as we only work in 2D. I know you are big in the "annotate in paper" brigade, but company standards are company standards, so we must annotate in the model!

So, unfortunately, my question still remains open.

Any ideas?
Title: Scale a block relative to viewport
Post by: ronjonp on March 30, 2005, 09:33:10 AM
Jonesy,

Here is a "frankensteined" version. It will grab the twist angle of the viewport and the scale. It applies the twistangle to the rotation of the block and uses the viewport scale for the scale of the block. This way the north arrow will always be the same plotted size.

Ron

Code: [Select]
(defun c:N-ROT (/ ent obj twist scale pt)

(vl-load-com)
(setvar 'tilemode 0)

  (setq ent (entsel "\nSelect viewport: "))
  (setq obj (vlax-ename->vla-object (car ent)))
  (setq twist (vlax-get obj 'TwistAngle))
  (setq scale (vlax-get obj 'CustomScale))
  (setq scale (/ 1 scale))
  (setq twist (/ (* twist 180) pi))

(setvar 'tilemode 1)
  (initget 1)
  (setq pt (getpoint "\nPick North Arrow location"))
(command
  ".-INSERT"
  "north.dwg"  ;change this line to the path where your north
                      ;block resides example: C:\\blocks\\north.dwg
  pt

  1
  1
  twist
  )
)


*edit* I was playing around with this a little more an realized that if a viewport is twisted and you place the arrow in modelspace....it will correspond to the twist angle  :oops: duh. So this would be good for inserting the north arrow in paperspace or change the roatation angle to 0 if you want to insert it in model.
Title: Scale a block relative to viewport
Post by: ronjonp on March 30, 2005, 10:24:52 AM
Try this one for modelspace block insert:

We put all of our north arrows in paperspace. the routine above should make it pretty easy to "know" where north is.....assuming north is the same as the twist angle of the viewport.

Code: [Select]
(defun c:N-ROT (/ ent obj twist scale pt)

(vl-load-com)
(setvar 'tilemode 0)

  (setq ent (entsel "\nSelect viewport: ")
        obj (vlax-ename->vla-object (car ent))
  )

  (setq twist (vlax-get obj 'TwistAngle)
        scale (vlax-get obj 'CustomScale)
        scale (/ 1 scale);edit this line to adjust size of block
        twist (/ (* twist 180) pi)
  )

(setvar 'tilemode 1)

  (initget 1)
  (setq pt (getpoint "\nPick North Arrow location"))
(command
  ".-INSERT"
  "north.dwg"  ;change this line to the path where your north
                      ;block resides example: C:\\blocks\\north.dwg
  pt
  scale
  scale
  0
  )
)
Title: Scale a block relative to viewport
Post by: jonesy on March 30, 2005, 10:59:18 AM
Thanks for your help. It was just what I wanted.

I will look at the coding to see if I can figure out what is doing what.

Kind regards
Title: Scale a block relative to viewport
Post by: ronjonp on March 30, 2005, 11:20:16 AM
Glad to of helped :). let me know if you need anything else.

Ron