Author Topic: Scale value of a Viewport  (Read 11704 times)

0 Members and 1 Guest are viewing this topic.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Scale value of a Viewport
« on: November 08, 2006, 02:30:54 PM »
Is there way to extract the value of user selected viewport.

I am wanting to write a routine revise a piece of text  base upon the scale of viewport.

Thanks.  I am getting tired of constantly updating my con doc grids

Oh by the way I am loving Firefox 2.0.  Automatic spell check Swweeeeeeeeettttttt :-)

I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Guest

  • Guest
Re: Scale value of a Viewport
« Reply #1 on: November 08, 2006, 02:54:53 PM »
You can use a field.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Scale value of a Viewport
« Reply #2 on: November 08, 2006, 02:58:45 PM »
Hi, 

assuming ent is the viewport ename :

(/ (cdr (assoc 41 (entget ent))) (cdr (assoc 45 (entget ent))))

or :

(vla-get-CustomScale (vlax-ename->vla-object ent))

If the viewport is active, you can just do :

(caddr (trans '(0 0 1) 2 3))
« Last Edit: November 08, 2006, 03:01:44 PM by gile »
Speaking English as a French Frog

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Scale value of a Viewport
« Reply #3 on: November 08, 2006, 03:47:34 PM »
You can use a field.
[voice of grass hopper]
I have heard of what you speak Master but I have concerns of the unknown.  Please explain.
[/voice]
Sorry the last 4 days have been 15 hour days of work.


(vla-get-CustomScale (vlax-ename->vla-object ent))
Thanks that got me what I needed. 
Now I just need to get it in the right format of Fractions   :-)

 
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Guest

  • Guest
Re: Scale value of a Viewport
« Reply #4 on: November 08, 2006, 04:12:55 PM »
Quote
[voice of grass hopper]
I have heard of what you speak Master but I have concerns of the unknown.  Please explain.
[/voice]
See attached video (hope this helps).

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Scale value of a Viewport
« Reply #5 on: November 08, 2006, 04:50:37 PM »
Thanks that did help. 
two things that I like about it were
  • it is linked to the viewport.  My original track was not going to be linked
  • It takes care of the formating issue of fractions.  I was having a hard time converting the decimal value to fractions.
my concerns are:
  • how could I automate this so that the user has just two picks;  the view port & and the text to change?
  • If the viewport is deleted, what happens to the field?

I am trying to make this simple as possible for my users.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Guest

  • Guest
Re: Scale value of a Viewport
« Reply #6 on: November 08, 2006, 05:01:40 PM »
Quote
how could I automate this so that the user has just two picks;  the view port & and the text to change?
See code below.  It's for adding an area field as mtext based on a close pline selection.  You should be able to hack it to work with vports.  I'm not well-versed in the ways of VLISP so....

Quote
If the viewport is deleted, what happens to the field?
The text would read as four dashes (---) because the info can't be found.

Code: [Select]
(defun C:FIELD-Area (/ a s1 index ent obj obj_ID txt)

   (vl-load-com)
   ;;get a reference to model space
   (setq *model-space*
          (vla-get-ModelSpace
            (vla-get-ActiveDocument (vlax-get-acad-object))
          )
   )

   ;; Set A = the entity and set B = Point for text
   (setq a (car (entsel)) b (getpoint "\n Select Point: "))
   ;;Call the function
   (linkedarea a b)
)


; From R.K. McSwain
; http://rkmcswain.blogspot.com/2006/09/create-field-linked-to-object.html

;;pass this function an entity and a point
(defun LinkedArea (ent pt / obj objID ip width str) 
;;convert the entity to an object
  (setq obj
   (vlax-ename->vla-object ent)
        ;;get the object ID
        objID (vla-get-objectid obj)
        ;;convert the point
        ip    (vlax-3D-Point pt)
        ;;set the width for the MTEXT
        width 0.0
        ;;set the string - this creates the field
        str   (strcat
                "%<\\AcObjProp Object(%<\\_ObjId "
                (rtos objID 2 0)
                ">%).Area \\f \"%lu2>%"
              )
  )
   ;;Create the MTEXT entity containing the field.
  (vla-addMText *model-space* ip width str)
)

(princ)


Hope this helps.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Scale value of a Viewport
« Reply #7 on: November 08, 2006, 05:10:34 PM »
Thanks.  I not well verse in Vlisp either but I am excellent hacker.  :-D
I will tear it apart tomorrow.
Thanks.  Now off to some Guinness and pasta  ^-^

I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Scale value of a Viewport
« Reply #8 on: November 08, 2006, 06:11:51 PM »
Give this a try:

Code: [Select]
(defun c:vp-scl (/ ID pt)
  (vl-load-com)
  (setq ID (vla-get-objectid (vlax-ename->vla-object (car (entsel))))
pt (vlax-3D-Point (getpoint "\n Select Point: "))
  )
  (vla-addMText
    (vla-get-paperspace
      (vla-get-ActiveDocument (vlax-get-acad-object))
    )
    pt
    0.0
    (strcat
      "%<\\AcObjProp Object(%<\\_ObjId "
      (itoa ID)
      ">%).CustomScale \\f \"1:%lu2%ct1%qf2816\">%"
    )
  )
)
« Last Edit: November 08, 2006, 06:16:50 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Andrea

  • Water Moccasin
  • Posts: 2372
Keep smile...

Guest

  • Guest
Re: Scale value of a Viewport
« Reply #10 on: November 09, 2006, 08:57:52 AM »
Give this a try:

Code: [Select]
(defun c:vp-scl (/ ID pt)
  (vl-load-com)
  (setq ID (vla-get-objectid (vlax-ename->vla-object (car (entsel))))
pt (vlax-3D-Point (getpoint "\n Select Point: "))
  )
  (vla-addMText
    (vla-get-paperspace
      (vla-get-ActiveDocument (vlax-get-acad-object))
    )
    pt
    0.0
    (strcat
      "%<\\AcObjProp Object(%<\\_ObjId "
      (itoa ID)
      ">%).CustomScale \\f \"1:%lu2%ct1%qf2816\">%"
    )
  )
)

Nice!  I think I can hack away at this to do other wonderous things.   Hmmmm.... :roll:

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Scale value of a Viewport
« Reply #11 on: November 09, 2006, 09:37:14 AM »
Give this a try:

Quote
(defun c:vp-scl   (/ ID pt)
.................
(vla-addMText)
    (vla-get-paperspace
      (vla-get-ActiveDocument (vlax-get-acad-object))

    (strcat
      "%<\\AcObjProp Object(%<\\_ObjId "
      (itoa ID)
      ">%).CustomScale \\f \"1:%lu2%ct1%qf2816\">%"
Thanks.   :-)
However I need to change a piece of DText.  The existing text (up to 16 instances) comes in on a CON DOC grid.
From > Scale:
To    > Scale: 1/4" = 1'-0

Like I said before I know nothing about VLA functions.

<Side note> How do I search in the Help for "ALL"  VLA functions pertaining to a certain object (or entity)?  Like this, I want to return all functions that handle (?? bad term) text.


http://www.google.ca/search?hl=fr&q=vpscale+lisp&meta=
Thanks Andrea I look at and it seems that it was similar to what RonJonp posted.  I did not try it, however if it if it is different from what Ronjonp's please let me know.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Scale value of a Viewport
« Reply #12 on: November 09, 2006, 11:16:10 AM »
I use this to get an object's properties:

Code: [Select]
(defun c:vlaxprop (/)
  (vlax-dump-object
    (vlax-ename->vla-object
      (car (entsel "\nSelect Entity to Display it's Data: "))
    )
    T
  )
  (textscr)
)

This code below will output the text as "Scale: 1' = 1'-0"

Code: [Select]
(defun c:vp-scl (/ ID pt)
  (vl-load-com)
  (setq ID (vla-get-objectid (vlax-ename->vla-object (car (entsel))))
pt (vlax-3D-Point (getpoint "\n Select Point: "))
  )
  (vla-addMText
    (vla-get-paperspace
      (vla-get-ActiveDocument (vlax-get-acad-object))
    )
    pt
    0.0
    (strcat "Scale: "
      "%<\\AcObjProp Object(%<\\_ObjId "
      (itoa ID)
      ">%).CustomScale \\f \"%lu4%pr8%ct2%qf2816 = 1'-0\\\"\">%"
    )
  )
)


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Scale value of a Viewport
« Reply #13 on: November 09, 2006, 12:29:11 PM »
I use this to get an object's properties:

Code: [Select]
(defun c:vlaxprop (/)
  (vlax-dump-object
    (vlax-ename->vla-object
      (car (entsel "\nSelect Entity to Display it's Data: "))
    )
    T
  )
  (textscr)
)

Wow what did you give me???  I feel like a small time crook that some how found himself in the big leagues.  8-) :-o :-D

See screen capture.

I see it return the property or data of object which by the way is the object that I want to insert the field into.  And I understand most of it, I think.

What is the second group "methods supported" do?  And what does the number in the bracket mean?
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Scale value of a Viewport
« Reply #14 on: November 09, 2006, 12:50:42 PM »
The methods and properties are ActiveX controls of the object.  They are pretty much the same as VBA.  To see and explanation look in the help files.  Get to the 'Developer Documentation' and then you will see a section called 'ActiveX and VBA Developer's Guide'.  In there you will see sections for properties, methods and objects, these are what you are looking for.  They are explained in VBA terms, so the syntax is a little different, but you have many people here who know what they are doing, so if the help isn't enough post a question.
Tim

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

Please think about donating if this post helped you.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Scale value of a Viewport
« Reply #15 on: November 09, 2006, 01:35:07 PM »
The methods and properties are ActiveX controls of the object.  They are pretty much the same as VBA.  To see and explanation look in the help files.  Get to the 'Developer Documentation' and then you will see a section called 'ActiveX and VBA Developer's Guide'.  In there you will see sections for properties, methods and objects, these are what you are looking for.  They are explained in VBA terms, so the syntax is a little different, but you have many people here who know what they are doing, so if the help isn't enough post a question.

Thanks Tim,

From what I gather from a quick pass am I correct to assume that I can not edit the text string, I have to delete the text and recreate it with the new text string?  I wonder if there is a Replace function?  I was really looking for just editing because the end goal routine is this will be an optional tool to my users.  I have a bunch of dinosaurs (sorry dino not you) that prefer to make multiple clicks to do same thing that a lisp can do.  I can't change that thought so therefore my tools or routines are distributed or set up for optional use. 
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Scale value of a Viewport
« Reply #16 on: November 09, 2006, 02:06:23 PM »
From what I gather from a quick pass am I correct to assume that I can not edit the text string, I have to delete the text and recreate it with the new text string?
Nope, you can change the string of an existing text string.
Code: [Select]
(vla-put-TextString
 (vlax-ename->vla-object
  (car
   (entsel "\n Select text entity to change: ")
  )
 )
 "This is a test!!"
)

Is this what you were thinking?  Sorry if I misinterpreted your intentions.
Tim

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

Please think about donating if this post helped you.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Scale value of a Viewport
« Reply #17 on: November 09, 2006, 02:22:24 PM »
From what I gather from a quick pass am I correct to assume that I can not edit the text string, I have to delete the text and recreate it with the new text string?
Nope, you can change the string of an existing text string.
Code: [Select]
(vla-put-TextString
 (vlax-ename->vla-object
  (car
   (entsel "\n Select text entity to change: ")
  )
 )
 "This is a test!!"
)

Is this what you were thinking?  Sorry if I misinterpreted your intentions.
No that is what I am exactly looking for.
Thanks. Now I am going to hack all this together. 
Thanks Tim & Matt.
I will be back.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Scale value of a Viewport
« Reply #18 on: November 09, 2006, 02:45:50 PM »
Good to hear Krushert.  One thing, not sure if you know or not, but when using the ActiveX controls in Lisp, you need to call (vl-load-com) at least once per Acad session, more is okay.

Let us know when you need help/finish your program.  Have fun.
Tim

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

Please think about donating if this post helped you.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Scale value of a Viewport
« Reply #19 on: November 09, 2006, 03:40:49 PM »
Good to hear Krushert.  One thing, not sure if you know or not, but when using the ActiveX controls in Lisp, you need to call (vl-load-com) at least once per ACAD session, more is okay.

Let us know when you need help/finish your program.  Have fun.
basicly you guys gave it all to me.  I swap your Put-textstring in lieu of Matt's addtext and then clean it up.

Code: [Select]
;;; VPort-Scale Lisp  11/09/2006  Ted Krush with a lot help from TheSwamp.org
;;; Adds the viewport scale factor to an existing textstring with use of a feild
;;;
(defun c:vpsc (/ ID)
  (princ)
  (vl-cmdf ".undo" "m")
  (vl-load-com)
  (setq ID (vla-get-objectid
     (vlax-ename->vla-object
       (car (entsel "\n Select Viewport Entity "))
     )
   )
  )

  (vla-put-TextString
    (vlax-ename->vla-object
      (car
(entsel "\n Select text entity to change: ")
      )
    )
    (strcat "SCALE: "
    "%<\\AcObjProp Object(%<\\_ObjId "
    (itoa ID)
    ">%).CustomScale \\f \"%lu4%pr8%ct2%qf2816 = 1'-0\\\"\">%"
    )
  )
  (princ)
)
This is a major time saver. and I did have fun.  :-)

Mucho Thanks Guys.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Guest

  • Guest
Re: Scale value of a Viewport
« Reply #20 on: November 09, 2006, 03:46:49 PM »
One slight change!

Quote
;;; VPort-Scale Lisp  11/09/2006  Ted Krush with a lot help from TheSwamp.org
;;; Adds the viewport scale factor to an existing textstring with use of a feild
;;;
(defun c:vpsc (/ ID)

I think I'm gonna pirate a copy of this and use to change entity values to the CTAB value.  We use that in our title blocks and just rename the layout tabs; also used for batch plotting.

Glad you got it working... I was having a heck of a time with this part:
Quote
1'-0\\\"\">%"
The slashes and quotes were throwing me for a loop.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Scale value of a Viewport
« Reply #21 on: November 09, 2006, 04:06:00 PM »
One slight change!

Quote
;;; VPort-Scale Lisp  11/09/2006  Ted Krush with a lot help from TheSwamp.org
;;; Adds the viewport scale factor to an existing textstring with use of a feild
;;;
(defun c:vpsc (/ ID)
Thanks for letting me know about my spelling.  I wish Lisp editor had a spell check.

Glad you got it working... I was having a heck of a time with this part:
Quote
1'-0\\\"\">%"
The slashes and quotes were throwing me for a loop.
Yeah what is that line doing  anyway
Code: [Select]
    ">%).CustomScale \\f \"%lu4%pr8%ct2%qf2816 = 1'-0\\\"\">%"
No that is what I am exactly looking for.
Thanks. Now I am going to hack all this together. 
Thanks Tim & Matt & Ronjonp[
I will be back.
Sorry Ronjonp  :oops:  I was interrupted and hit the post.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Guest

  • Guest
Re: Scale value of a Viewport
« Reply #22 on: November 09, 2006, 04:16:51 PM »
Yeah what is that line doing  anyway
Code: [Select]
    ">%).CustomScale \\f \"%lu4%pr8%ct2%qf2816 = 1'-0\\\"\">%"
It's basically telling the text (or mtext or whatever) how to display the viewport's scale.

The attached image might help to explain things better.

All of this gobble-dee-goop (CustomScale \\f \"%lu4%pr8%ct2%qf2816 = 1') is contained in the field expression section at the bottom of the dialog box.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Scale value of a Viewport
« Reply #23 on: November 09, 2006, 04:26:43 PM »
Yeah what is that line doing  anyway
Code: [Select]
    ">%).CustomScale \\f \"%lu4%pr8%ct2%qf2816 = 1'-0\\\"\">%"
It's basically telling the text (or mtext or whatever) how to display the viewport's scale.

The attached image might help to explain things better.

All of this gobble-dee-goop (CustomScale \\f \"%lu4%pr8%ct2%qf2816 = 1') is contained in the field expression section at the bottom of the dialog box.

Ah hah.
hmmmmmm.  me thinking.
I might modify something else too. 
Thanks.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Scale value of a Viewport
« Reply #24 on: November 09, 2006, 05:20:53 PM »
Glad you got what you were looking for :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Scale value of a Viewport
« Reply #25 on: November 09, 2006, 05:29:20 PM »
One slight change!

Quote
;;; VPort-Scale Lisp  11/09/2006  Ted Krush with a lot help from TheSwamp.org
;;; Adds the viewport scale factor to an existing textstring with use of a feild
;;;
(defun c:vpsc (/ ID)

I think I'm gonna pirate a copy of this and use to change entity values to the CTAB value.  We use that in our title blocks and just rename the layout tabs; also used for batch plotting.

Glad you got it working... I was having a heck of a time with this part:
Quote
1'-0\\\"\">%"
The slashes and quotes were throwing me for a loop.



We do the same thing here with the CTAB field....thanks for the idea.
Code: [Select]
(defun c:ctabfield (/)
  (vla-put-TextString
    (vlax-ename->vla-object
      (car (entsel "\n Select text: "))
    )
    "%<\\AcVar ctab \\f \"%tc1\">%"
  )
  (princ)
)

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Guest

  • Guest
Re: Scale value of a Viewport
« Reply #26 on: November 09, 2006, 07:41:29 PM »
Quote
We do the same thing here with the CTAB field....thanks for the idea.
You're welcome.