Access to Dimension Line text?
-
No access to dimensions.
When you iterate dimensions they are returned to SketchUp Ruby as DrawingElements, and only way to workout that they are DrawingElements is checking the typename. But there are no methods for getting or setting any properties.
-
Thanks.
When you get a Dimension Line as a drawing element, perhaps by the user selecting it, can you get its properties such as length?
Perhaps it would still be possible to do what I am thinking of, not by accessing the text of the dimension line but just by accessing its length, thus taking advantage of the fact that it stays attached to the moved contour line.
Also, I suppose I should have asked this in the first place, are Callout Text object accessible to where the displayed text could be programmatically changed?
Thanks again,
August -
@august said:
When you get a Dimension Line as a drawing element, perhaps by the user selecting it, can you get its properties such as length?
No - you can not get set any dimension properties. You can select a dimension entity - because that's pretty much all you got, a generic
DrawingElement
entity.` Sketchup.active_model.selection[0]
#Sketchup::Drawingelement:0xc2bc33cSketchup.active_model.selection[0].typename
DimensionLinearSketchup.active_model.selection[0].class.ancestors
[Sketchup::Drawingelement, Sketchup::Entity, Object, Kernel]`@august said:
Also, I suppose I should have asked this in the first place, are Callout Text object accessible to where the displayed text could be programmatically changed?
Sketchup::Text
http://code.google.com/apis/sketchup/docs/ourdoc/text.html
Entities.add_text
http://code.google.com/apis/sketchup/docs/ourdoc/entities.html#add_text -
You can get a few more properties of a Dimension - but not very usefully...
Select a dimension that's 1m long... In the Ruby Console type/copy this
` d=Sketchup.active_model.selection[0]#Sketchup::Drawingelement:0xb8232f4
bb=d.bounds
#Geom::BoundingBox:0xb12e9d0
bb.width.to_mm
1000`
Hooray! [you think] we have the dimension's 'length' - BUT NO we don't -unless it's been drawn with it's length in the X/red axis!
If it were drawn in the Y/green axis then the result might be '150' which is the offset not the length of 1000 etc and angled dimensions are hopeless...
As there is no way of getting a dimension's 'transformation' then getting its bounds is somewhat limited in its use -
Thanks TIG.
Clear, helpful ... and frustrating.
Oh well. It seemed to be a good idea at the time.
Hmm. Maybe I don't need the Dimension Line at all, at least for the Contour Line case. (The tiny dimension case, I am stuck for ideas.)
Maybe I could add an attribute to a Text Entity that would save the Object ID of the Contour Line. Save all of those special Text Entities in a List.
Loop through the list and for each Text Entity, get the attribute and the Object ID, determine the elevation of the ID-ed Object, format that, insert it as the Text.text.
I had thought that I could use parallel lists of Text Entities and Contour Lines, but I think it will be cleaner to add an Attribute. That will allow you to select a single Text Entity and update it.
Hmmm. If I have an array of Text Entities that I'm holding onto and the user deletes one of them, what happens to the array? I presume it does not automatically shorten, it now has an element that points to a Null Entity, right?
While a user will have to use my "Magic Contour Line Add Tag" function to add a linked Text Entity, they are not so limited in deleting. I cannot be sure that they would always use my "Magic Contour Line Delete Tag" function for deleting.
So it would be best to just let them Delete normally and I figure out what they have done when I stumble upon a Null Entity in the list and just clean it up myself on the spot.
This is beginning to sound more do-able than I had feared.
For the contour line, I think I would need to look at the min Elevation and the max Elevation and if they are different, display both, if they are the same, display a single value.
I'm starting to think it could be made generic.
Right Click on any object and select "Add TAG". That would pop up a menu of attributes to display, X, Y, Z, MIN [X,Y,Z], MAX [X,Y,Z], [X,Y,Z]-extent, ... ObjectID, etc. Optional identifier (e.g., "Min-Y =").
Select the item and a Text Entity is created that displays that value.
That could be useful.
If this idea inspires anyone, please feel free to run with it. Just let me know.
It will be a week or two before I can begin banging on this. I have time for brainstorming and testing, but coding will be slow because of how many of these pieces I've never done before.
Thanks again for pointers.
August
-
If that's ALL you want... then find my 'Height Datum Coords' tool...
Just pick the contour to add the height above your [preset] datum...
If you move the text up/down then the value shown changes... -
@august said:
Maybe I could add an attribute to a Text Entity that would save the Object ID of the Contour Line. Save all of those special Text Entities in a List.
What did you have in mind for "Object ID"? Entity.entityID is not persistent between sessions.
-
@august said:
Maybe I could add an attribute to a Text Entity that would save the Object ID of the Contour Line. Save all of those special Text Entities in a List.
@unknownuser said:
](http://code.google.com/apis/sketchup/docs/ourdoc/entity.html#entityID)":1pgf4c48]The entityID is not persistent between sessions.
Object.object_id is assigned by Ruby, and also is not persistent between sessions.
"%10.6f" % Time.now.to_f returns a Float (converted to a String,) value of seconds (to 6 decimal places,) since the epoch began.
If you do not call Time.now.to_f twice in the same statement, it should always return a unique numerical string. If you are creating these "ids" in a loop, you can always be sure, the next iteration gives a new value by inserting a sleep statement within the loop's block, OR keep track of the last "id" created, and compare them. If they are the same.. create another, until the new one is different.
Keep in mind String compares are slow.. so you may wish to keep the "id" as a Float, for speedier compares.
Perhaps compares may be faster for Integer (and less memory, because there is only 1 of each ordinal for the entire set of integers in Ruby,) so you could multiply by 1_000_000 and use .to_i then store the "id" as a usec integer.
Or maybe an Array id:
%(#BF0000)[t = Time.now
id = [ t.to_i, t.usec ]] -
I had forgotten that Entity or Object IDs are not persistent. Neither are Arrays.
Right now TIG's Add Height from Datum seems to handle the basic idea for contour lines. But it is self-contained, referencing the hight of the Text Element point itself. To display data in a Text Element about another object means linking the entities, which is, of course, where the Unique Identifiers come in.
Thanks, Dan, for a great idea on where to get unique identifiers to add to an object's attributes.
It would probably require building a Lookup table, and rather than do that when you open the file, and thus do it for every file, it would be better to it when you manually access a menu item that updates the Text Entity Tags.
I'm going to let this one percolate for a while. If most of the substructure had to be created to do the contour lines and extending it was the simpler part, that's one thing. But since the contour lines is solved and extending it is not really extending anything, it's creating a whole new methodology, that's another thing.
Thanks again to all.
August
-
@august said:
I had forgotten that Entity or Object IDs are not persistent. Neither are Arrays.
...
It would probably require building a Lookup table, ...The normal way is to attach an attribute dictionary to the items you wish to "link" and save the "linking id" into each dictionary.
%(#BF0000)[t = Time.now
object1.set_attribute('DictName','Link',[t.to_i,t.usec])
object2.set_attribute('DictName','Link',[t.to_i,t.usec])]
Saving the file, saves the attributes.The next time the file is opened, you can iterate the entities, and build a temporary session lookup table (an Array or Hash,) by comparing the timestamp array attributes of certain types of entities, that have the specific named dictionary.
During the session you CAN use the entityID or object_id methods. -
@dan rathbun said:
The next time the file is opened, you can iterate the entities, and build a temporary session lookup table
Doing that automatically for each entity would probably make SketchUp crawl to sludge when loading large models.
-
@thomthom said:
Doing that automatically for each entity would probably make SketchUp crawl to sludge when loading large models.
That is what I was alluding to when I wrote:
@august said:
It would probably require building a Lookup table, and rather than do that when you open the file, and thus do it for every file, it would be better to it when you manually access a menu item that updates the Text Entity Tags.
My thought is that you should manually trigger the updating and table-building process, maybe with a progress bar, so that at least it only happens when you are prepared for it happening, and most especially it does not happen on every file, whether the tool is used or not, just because the Plugin happens to be loaded.
It might be a timesaver to have the option of scanning the whole file, or just the selected part of the file.
-
FYI, for anyone following this, now or later, here is the link to TIG's plugin:
[Plugin] Add Height from Datum v1.3 -
@thomthom said:
@dan rathbun said:
The next time the file is opened, you can iterate the entities, and build a temporary session lookup table
Doing that automatically for each entitywould probably make SketchUp crawl to sludge when loading large models.
For the record, I never said each entity, I said ...
@dan rathbun said:certain types of entities, that have the specific named dictionary
.. which is similar to how the Dynamic Components extension operates. But it uses observers to know when to "update' or redraw the entites it is concerned with.
It would be nice to have a "when_idle" block to do work like this when nothing else "heavy" is going on.
-
-
post removed. (Too tired, low confidence in what I wrote.)
Advertisement