Author Topic: Dimension Text Override  (Read 5392 times)

0 Members and 1 Guest are viewing this topic.

Bill Tillman

  • Guest
Dimension Text Override
« on: January 27, 2012, 03:39:27 PM »
I have some dimensions in an existing drawing which I want to add a text override to using VLISP. In studying and searching for a method to do this I keep finding code which will ask the user to select the dimensions or uses entlast or it will use the (ssget "_X") method to select all the dimensions. Neither of which works my project.

I have a method of identifying the properties and methods of the dimensions I'm interested in and one of those properties identified is the handle, which I would hope would be a good field to use as this program will be run many times and I need the property relating to the dimension to remain static over time.

OK, so here is what I have thus far and I have been able to get this to insert the text override but it's not using the method I want:

Code: [Select]
(defun C:fixit ()
  (vl-load-com)
  (setq SelSet (ssget "_X" '((0 . "DIMENSION"))))
  (setq Ent (ssname SelSet 1))
  (setq Obj (vlax-ename->vla-Object Ent))
  (vlax-put-property Obj "TextOverride" "This is the DOR Text")
)

This is easy to use because the drawing I'm testing it on has only one dimension. The drawings I need this to work on have many dimensions and of those I will only be interested in 4 or 5 of them. So my plan is to use a quick snippet which will let me identify something unique and static about those 4 or 5 dimensions (individually, of course) and then write a line of code for each on which will insert the text override needed for each one. Each text override for each dimension will be different. It will not be a shotgun blast to override all of them with the same text. Thus the need for the individual line for each dimension.

The code I use to identify the properties of the dimensions will be a stand alone which I run once on the drawing's dimensions. Once I have something unique identified about the dimensions needed, I will set this code aside and the main program will be the one which runs and makes the changes. As I work with new drawings, this separate code will be used again but only to quickly get a name of identifier for the dimensions which can be used in the main code. Hope I've explained this clearly.

The confusion on my part is how to get the information I know about this dimension to work in that line of code which writes the override. I can see from using the command prompt:

Command: !Obj
#<VLA-OBJECT IAcadDimAligned 0a6dd67c>

But if I enter that information like this:

Code: [Select]
(vlax-put-property <VLA-OBJECT IAcadDimAligned 0a6dd67c> "TextOverride" "This is the DOR Text")
of course this does not work.
« Last Edit: January 27, 2012, 04:10:47 PM by Bill Tillman »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dimension Text Override
« Reply #1 on: January 27, 2012, 04:34:53 PM »
Obj is a variable holding the information you need.
In this case the object pointer.

Try this one:
Code: [Select]
(defun c:test (/ ent obj)
  (setq ent (car (entsel "\nPick the dimension.")))
  (setq obj (vlax-ename->vla-object ent))
  (vlax-put-property obj "TextOverride" "This is the DOR Text")
  (princ)
)
« Last Edit: January 27, 2012, 04:48:46 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Bill Tillman

  • Guest
Re: Dimension Text Override
« Reply #2 on: January 27, 2012, 05:17:40 PM »
Many thanks for your reply. But let me clarify this a little more. I can't depend on the user to select the dimension. I need to have the code simply make the dimension overrides automatically. The users will know nothing or very little about how to use AutoCAD. It's a complicated process where the sales people will just enter data into an Excel form and click a button. My VB and VLISP code takes care of everything from there.

I follow you that Obj has the information I need, but I need to write several lines of this code to change the 4 or 5 dimensions in the drawing. Which is why I need to know what information is in Obj, because if I !Obj it will give me a line like #<VLA-OBJECT IAcadDimAligned 0a6dd67c> which I can't figure out how to merge into the line

Code: [Select]
(vlax-put-property obj "TextOverride" "This is the DOR Text")
I realize this sounds chaotic, but believe me there is a method to my madness.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dimension Text Override
« Reply #3 on: January 27, 2012, 05:46:36 PM »
In your example the dimensions are contained  in a selection set which can be iterated through like this.
Code: [Select]
(defun c:fixit (/ i selset ent obj)
  (vl-load-com)
  (setq selset (ssget "_X" '((0 . "DIMENSION"))))
  (setq i -1)
  (while (setq ent (ssname SelSet (setq i (1+ i))))
    (setq obj (vlax-ename->vla-object ent))
    (vlax-put-property obj "TextOverride" "This is the DOR Text")
  )
  (princ)
)

I'm not at all sure what you are looking for.
« Last Edit: January 27, 2012, 06:14:46 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Bill Tillman

  • Guest
Re: Dimension Text Override
« Reply #4 on: January 27, 2012, 07:10:50 PM »
Thank you again sir. And I realize on the surface this looks confusing. Let me see if I can describe it more clearly.

The drawing I'm working with has about 20 or so dimensions on it. Out of these 20 or so dimensions, I will be targeting only 5 of them for text override. I know which 5 I want so I will call them Dim1, Dim2....Dim5. Each dimension will get it's own individual text override. I should add here that the text override will not be happening when I'm running the code. It will happen when another user, who is not a normal CAD person will be executing another VBA code coming out of Excel. So I hope that explains why I cannot choose all the dimensions of use any selection method.

The trouble I'm having is I need to grasp what Obj (in the example code above) is identifying about these dimensions. I'm still a newbie to the Collections, Objects and Methods for Active X in VLISP and I cannot figure out how to make something like this happen:

Code: [Select]
  (vlax-put-property obj_for Dim1 "TextOverride" "56")
  (vlax-put-property obj_for Dim2 "TextOverride" "62")
  (vlax-put-property obj_for Dim3 "TextOverride" "22")
  (vlax-put-property obj_for Dim4 "TextOverride" "33")
  (vlax-put-property obj_for Dim5 "TextOverride" "24")


When I run the code submitted in my first post, with only 1 dimension in the drawing, it's easy to isolate obj and ask the command line to print it using !. That will yield the results of something like:

#<VLA-OBJECT IAcadDimAligned 0a6dd67c>

but of course I cannot enter that in lieu of obj_for_Dim1, the code just crashes. I realize this is some kind of format the vlax-put is looking for but I'm sorry I just don't know enough about it yet to put my fingers on it. So in essence I'm asking how would I go about writing out in long form (or short form) the value of obj_for_Dim1, etc... so each line would execute like it does above. I have some code which can dump all Properties and Methods for selected Objects. I run this separately to identify what I assume will be the Handle of the dimension objects and write down each one for the 5 dimensions. Then somehow I need to feed this information into those 5 individual lines of code to get only the correct dimensions set with their respective text override. Please note that I don't know for certain if Handle is the field I want or if that is even what obj is being associated with when it's assigned by the
Code: [Select]
(vlax-ename->vla-object ent) statement.

To continue with my clarification, I cannot use the ssget "_X" method because that will grab all 20 dimensions. I cannot use entsel because that defeats the whole automation effort and worse the end users of this code will not have a clue about which dimensions to pick. That's why I'm automating it.
« Last Edit: January 27, 2012, 07:13:56 PM by Bill Tillman »

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Dimension Text Override
« Reply #5 on: January 27, 2012, 07:22:35 PM »
Post a sample drawing. Ssget x should work for you ... You just apply your conditionals to the  overall selection.

« Last Edit: January 27, 2012, 07:26:15 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Bill Tillman

  • Guest
Re: Dimension Text Override
« Reply #6 on: January 27, 2012, 07:41:45 PM »
OK, I think I may have got it...handent...seems to be doing the trick...like this:

Code: [Select]
(setq Ent (handent "1AF"))
"1AF" is the handle of one of the dimension objects I want to tackle...Will report back with more results. This looks promising. Oh yes, a nice little code snippet from afralisp called "haveadump" is what gets me the handle and everything else. I need to scutinize this to get the printout to just give me the handle and not 3 million other pieces of information I'm not interested in at the moment.

ronjonp...thanks but remember that ssget "_X" will grab all 20 dimensions and I will never know which ones to throw out, etc....I think this method with handent is going to work out...brb!

Bill Tillman

  • Guest
Re: Dimension Text Override
« Reply #7 on: January 27, 2012, 08:00:32 PM »
BINGO:

It works, and works quite well. I know I sound crazy but I knew this could be done. It had to be otherwise I would be looking pretty stupid come Monday morning because they told me it couldn't be done.

In a nutshell, this snippet allows me to individially select the dimensions objects and dump the properties to the text window. I quickly jot down the handle for each dim object and then this program gets put away. It had nothing to do with the main code which the users run when they launch the Excel VBA code. But I included it here to maybe help others and maybe to explain why I sound so crazy.

Code: [Select]
(defun C:HaveaDump ( / ent)
  (vl-load-com)
    (while
        (setq ent (entsel))
        (vlax-dump-object (vlax-Ename->Vla-Object (car ent)) T)
      );while
    (princ)
)

Remember, after I write down the handles for the dim objects I want, the above code gets shut down and put away. It is not used at all in the main code I'm developing.

Then this little snippet will be added to the main code and it will take care of the dimtext overrides I need. Now to figure out when there is a fraction in the number and add formatting for diagonally stacked fractions. You metric system users have us yanks beat on that point.

Code: [Select]
(defun C:fixit ()
  (vl-load-com)
  (vlax-put-property (vlax-ename->vla-Object (handent "1AF")) "TextOverride" "DIM 1 OvrRd")
  (vlax-put-property (vlax-ename->vla-Object (handent "20A")) "TextOverride" "DIM 2 OvrRd")
  (vlax-put-property (vlax-ename->vla-Object (handent "1EE")) "TextOverride" "DIM 3 OvrRd")
  (vlax-put-property (vlax-ename->vla-Object (handent "1FC")) "TextOverride" "DIM 4 OvrRd")
)
« Last Edit: January 27, 2012, 08:04:53 PM by Bill Tillman »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Dimension Text Override
« Reply #8 on: January 27, 2012, 08:04:37 PM »

Whoa .. hard coding handles will lead to dispair.

I haven't read the thread but that just jumped out at me.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Dimension Text Override
« Reply #9 on: January 27, 2012, 08:16:27 PM »
Is this override only required in ONE drawing ?

How many times do you expect each override will be required to each dimension object ?

... in each session ?
 ... in the document lifetime ?

How many people will run this routine ?
Who will decide which Dimensions are to be overwritten ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Dimension Text Override
« Reply #10 on: January 27, 2012, 08:21:06 PM »

Seems to me you may be best served writing the handles (after the initial selection) to a dictionary record in the drawing, then access the dictionary record programatically when your routine does the update.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Bill Tillman

  • Guest
Re: Dimension Text Override
« Reply #11 on: January 27, 2012, 08:23:16 PM »
OK, I would like to address that point....I have these drawings which have dimension objects on them. According to what I've read, the handle is the one object which does not ever change over the life of a drawing. And that's why I'm doing it this way. I think you may be headed down the path like the others that this is an interactive process, which it is not. A user who never uses AutoCAD will be able to answer a few questions in Excel, click a macro button and then sit back while AutoCAD launches and prepares their drawing for them. It all happens in the blink of an eye. And I can't have them interacting with the process in anyway.

However, as someone who is still very new to VLISP I'm all ears for advice and comments.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Dimension Text Override
« Reply #12 on: January 27, 2012, 08:27:50 PM »
in that case


Seems to me you may be best served writing the handles (after the initial selection) to a dictionary record in the drawing, then access the dictionary record programatically when your routine does the update.

will allow you to set-up each drawing without manually recording the handles for each drawing

I assume the interaction will be different in each drawing ?
and I assume you are starting with a template that has the dimensions in it.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Bill Tillman

  • Guest
Re: Dimension Text Override
« Reply #13 on: January 27, 2012, 08:38:51 PM »
Is this override only required in ONE drawing ?

These are drawing templates, not in the AutoCAD sense of templates. These will not be drawings worked on by AutoCAD designers, in fact they won't be worked on at all. The whole point of my assignment is to make it so the sales people can enter a few dimenions in a spread sheet and a sales presentation drawing will be prepared quickly and accurately.

Quote
How many times do you expect each override will be required to each dimension object ?
The override will happen many times over, but the drawing will be for a different sized product each time. But to answer your question the override will happen only once in each session. The user will have the choice to save the file under a different name with the overrides intact or just trash the thing and start over or whatever...

Quote
... in each session ?
Does this matter with the process I'm using, I don't believe so.
Quote
... in the document lifetime ?
again, it doesn't really matter for this process.

Quote
How many people will run this routine ?
A dozen or more, and if it works like I think it will maybe many more in other branch offices.
Quote
Who will decide which Dimensions are to be overwritten ?
I do but it's a pretty rigid process. The dimensions overridden represent the same fields everytime the process is run so it is very repetative...which means it's ideal for automation.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dimension Text Override
« Reply #14 on: January 27, 2012, 08:58:12 PM »
OK I think I have figured out what you are after.
To identify those dimension's in a later drawing session you could mark them with a text override that you could identify
or you could use there "handles" or you could tag them with an xdata marker. I favor the latter.
The markers could be the same for many drawings where the Handle is specific to a particular drawing and
therefore less flexible. The text override as a marker is less elegant and could be altered by a user by mistake.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.