Thanks, I'm asking about ways to interact with the text: getting, setting.
Posts made by ittayd
-
RE: Weird DimensionLinear behavior
-
RE: Bounds change depending on active context?
I think the docs do mention returning coordinates in model space. I read "model space" to mean a global standard coordinate system. So I would expect the coordinates to never change no matter what entity is opened.
And, I wouldn't mind the coordinates changing if
contains?
would have acted sanely, always returning true to a point that is inside the group -
RE: Knowing the ComponentInstance a DimensionLinear is attached
dim.start[0]
will return a Vertex or Edge. How do I know the ComponentInstancedim.start[0]
is part of? As I wrotedim.start[0].parent
returns a ComponentDefinition. -
Bounds change depending on active context?
I created a rectangle, grouped it and then grouped the group.
I select the inner group and print its bound's corners:
I then select the outer group and print the inner group's bounds corners again:
The values change.
My problem is that I have a point (the start of a dimension) that is then deemed outside of the bounding box of the group:
But if I open the outer group, it is OK:
How can I make sense out of this?
-
Knowing the ComponentInstance a DimensionLinear is attached
I have a dimension attached to a component instance (it moves with it, changes when it is stretched, etc.). Using the API,
dim.start[1].parent
returns a ComponentDefinition. This of course doesn't tell me which instance it is attached to. Is there a way of knowing? Or is it a bug?(A brute force method is to go over every instance, iterate over all its vertices and compare with the one of the dimension. I'm looking for something more elegant, and that will work when attaching to an edge etc.)
-
Weird DimensionLinear behavior
Dimensions that are inside components change their texts based on the instance scale. This is true in the GUI as well as the API.
For example, in the images below, the rectangles are instances of the same component. I open the left one, get a dimension entity and its text and then open the right one and get the text of the same entity which changed. A similar thing happens for positioning
Is there a way to get all texts of the dimension instance? Is there a way of programmatically change one?
(I'm using SU 17.2.2555)
-
Undo model observer - when to remove?
I want to attach a ModelObserver to react to onTransactionUndo (is that the right approach to undo an operation when there's more than geometry?). But when do I remove it? Is there a way to know the limit of the undo stack and when my operation is out of it?
-
RE: Flags parameter in a tool's onKeyDown/Up
@dan rathbun said:
@ittayd said:
Hitting ctrl+shift as ctrl, keeping pressed and then shift:
onKeyDown prints 11101 on hitting ctrl, note again the flags mean both ctrl and shift are down
onKeyDown prints 101010 on hitting shift (when the ctrl is still down) which suggests it "forgets" the shift is down.It seems you are making a fundamental mistake. In this example in the quote above, the detected KEY is the SHIFT key, and it is what is causing the
onKeyDown()
callback to fire, and it's keycodeVK_SHIFT
will be stored in thekey
argument.So, then you do not detect IT within the
flags
bitfield, because you already know what the firing key is.Instead, at this point in time, you check the
flags
bitfield for whatever other modifiers are associated with this press of the SHIFT key.OK, so you took just the last line of a whole example:
- When I press'shift' only, without 'ctrl' first, I get 101010. As if ctrl is pressed, but it is not.
- And even with the 'ctrl' pressed first, what is the meaning of the 6th and 2nd bits?
- When I press 'ctrl' only, without shift, I get 11101, as if ctrl and shift are pressed.
- And also, what is the meaning of the 5th and 1st bits?
- I get the same codes in onKeyDown and onKeyUp regardless of whether I press ctrl with shift already pressed or not or when I press shift and ctrl is pressed before or not.
And sure, the 'key' parameter does hold the code for ctrl and shift, and I ended up maintaining an instance variable to flip bits on and off when the callbacks are called. But I'm still confused as to the meaning of the flags parameter.
I'd like to mention that I have 16 years of professional programming: 1.5 years of Ruby, 8 years Java, 2 years of Scala, 5 years of C/C++ and in particular 1 year of Linux kernel development (in the virtual memory handling subsystem), as well as other assorted languages. In particular, I had many chances of doing bit manipulation of variables as well as work with bit sets.
All of that doesn't help me in understand the values of the flags parameter which in the case of onKeyDown/onKeyUp doesn't make sense to me. For comparison, in onLButtonDown, the flags are 1001 if ctrl is down when the button is clicked, 101 if shift is down and 1101 if both and just 1 when nothing is pressed. These are consistent with showing the value of the modifier keys, but inconsistent with the values I listed in my original post.
-
RE: Flags parameter in a tool's onKeyDown/Up
@dan rathbun said:
@ittayd said:
onKeyDown prints 101010 on hitting shift (when the ctrl is still down) which suggests it "forgets" the ctrl is down.
Why do you say this, when it is clear that the 4th bit (for CTRL modifier) is set ?
Typo. ctrl should be shift. But it is pretty obvious from the other examples (as well as this one) that the flags values are probably the bit set they were meant to be
-
RE: Flags parameter in a tool's onKeyDown/Up
@dan rathbun said:
Re-reading your original post the second paragraph is not at all clear. Ie: Run-on sentences. Not stating what callback (onKeyUp/onKeyDown) you are referencing.
Sorry if my message wasn't clear, English is not my native language (I don't even know what run-on sentences mean) and I wrote the post after a couple of hours of frustration. I edited it to make it clearer
I couldn't find code that demonstrated the use of flags in onKeyDown or onKeyUp (including searching my plugins folder, github, google).
-
RE: Handling advanced selection in a tool
So send_action is async, so the code that calls it returns immediately
-
RE: Handling advanced selection in a tool
Just found Sketchup.send_action. Will try to explore it.
-
RE: Flags parameter in a tool's onKeyDown/Up
@dan rathbun said:
Each bit in a bitfield represents a boolean switch for some feature.
In this case, is it whether a certain key's flag is sent to an onKey... callback.
I'm aware of what the flags are supposed to be and how to do bit manipulation, but the values make no sense. E.g. on ctrl then shift, the callback for the shift press doesn't pass on flags that show that ctrl is pressed
-
Handling advanced selection in a tool
I'm writing a tool in which I want a first step, then a step to allow the user to pick several entities and then more steps to manipulate them.
The problem is how do I allow the user to select the entities? I tried handling entity and window selection with PickHandler, then added modifier keys handling for add/remove/toggle, now I'm about to handle open & close of groups... It just seems too cumbersome.
Is there a way to utilize sketchup's own selection tool? So the user starts my tool, selects entities using the usual way and then gets back to my tool for the next steps. I can try reorganizing the tool so it expects a selection when it starts, but I want to see if I can do things the way I want.
-
Flags parameter in a tool's onKeyDown/Up
What is the meaning of the values of the flags parameter to the key callback methods in a tool? I understand they are supposed to show what modifier keys are pressed, but their value in the callback methods is confusing to me.
It is worth mentioning that shift has the value of 4 (100 in binary, or the 3rd bit) and ctrl is 8 (1000 in binary, or the 4th bit)
Adding
puts '%32b' % flags
to both onKeyDown and onKeyUp, I see the following:
Hitting ctrl:
onKeyDown prints 11101 (meaning, so it seems, that both ctrl and shift are pressed)
onKeyUp prints 1100000000011101.
Hitting shift:
onKeyDown prints 101010 (ctrl is pressed)
onKeyUp prints 1100000000101010
Hitting ctrl+shift as ctrl, keeping pressed and then shift:
onKeyDown prints 11101 on hitting ctrl, note again the flags mean both ctrl and shift are down
onKeyDown prints 101010 on hitting shift (when the ctrl is still down) which suggests it "forgets" the shift is down.
Similarly when releasing the keys, the values are for shift and ctrl onlyI'm trying to make sense of it instead of keeping my own state of when ctrl and shift are pressed and released.
I couldn't find code examples that use flags in onKeyDown and onKeyUp either -
How to create a selection window in a tool?
I want to create a tool that allows to select several entities by either picking them or a selection window. But how do I draw the selection window?
-
RE: How to implement entity selection "wizard"
Thanks. And how do I pick elements one by one? Do I need to listen to mouse clicks or is there something that takes care of the flow for me?
-
How to implement entity selection "wizard"
In Sketchup most of the tools contain a sort of "wizard" where the status line tells you what to pick and then when you pick it, what to pick next, etc. How can I do this in an extension?
-
RE: Extension that creates a shell of an object?
So then I can't apply outer solid on a component that contains groups? my alternative is to explode an instance and then "fiddle" with the groups?
-
RE: Extension that creates a shell of an object?
So how do I set up the model correctly? I tried outer-shell on my real model and it didn't work. Also, my model is quite complex, so is there a way to quickly fix it so outer-shell would work?