Thanks a lot!
Posts made by Nick60
-
RE: What version of Ruby should I start learning?
Regarding the Ruby 2.0 shift, what's appening to the Sketchup 2014 API ?
It seems the API documentation is still the old one, out there, or at least I coudn't find nothing new about it and that sound strange to me because SU 2014 did introduced some new things (like BIM classification) so I expect to use it also programmatically.Another really important point would be the avaibility of a list of breaking changes (if any) so we can check ours plugins to remove potential bugs.
Any help will be really appreciated.
-
RE: How to get the saved file path
@thomthom said:
Observer bug?
Hi thomthom, can you please remove the question mark?
I've spent (lost...) two days to find a solution, and wrote a lot about it. Thanks god TIG helped me finding a workaround.
But now we can surely say that is a bug.
And I've already filled the form you pinned for it. It's a pity that we can't track the bug, nor vote for it, otherwise I'd begged you for a vote!
(Ok, this reply was only an excuse to thank TIG one more time!)
and... ops! also the timer seems to have a bug because it doesn't stop even if the repeat flag is false
-
RE: How to get the saved file path
After some experiments, I'd like to add two things:
-
The Timer seems to ignore the no-repeat flag, so if the code (a delegate, tech speaking ) use more time than the timer interval, the timer start a new execution of the code. That's why the UI.messagebox create such a mess...
-
The solution is to move the stop.timer execution at the very begin of the code:
class MyModelObserver < Sketchup;;ModelObserver def onPostSaveModel(model) timer_id = UI.start_timer(0.5,false) do UI.stop_timer(timer_id) msg = "OnPostSaveModel; \n" + "- Path = '#{model.path}' \n" + "- Title = '#{model.title}' \n" + "- Dir.pwd = '#{Dir.pwd}'" UI.messagebox(msg) # Generate and save xml report # ... end end end
Thanks again.
-
-
RE: How to get the saved file path
Hi TIG,
thanks a lot, your workaround is great, and you really saved my life!
Thank you also for the detailed explanation of the unreliability of the Dir.pwd.
About the AppObserver, I already use it to attach the model observer to the model, as you wrote, so non problems with that .As I said, the whole observer set should be revised. Look at some oddities:
- We have the onNewModel and onOpenModel, but where is the onCloseModel?
- The onQuit is useless, because when fired the active_model is already gone with the wind...
- The Model observer has onBeforeComponentSaveAs and onAfterComponentSaveAs, but also onPreSaveModel, onSaveModel and onPostSaveModel: they used the words "Before" and "After" but also "Pre" and "Post". This is non consistent and show that there isn't a coherent and organic view of the complete set.
I do hope that version 9 will do a complete redesign of events and observers.
We need more control on what the user do, also to prevent him on doing some things. I'm developing a program where I need to prevent the user to edit some component definitions and there is no simple way of doing that. But this is another story...
Anyway, thanks again for your precious help.
-
RE: How to get the saved file path
Hi TIG,
second first: I'm talking about the onPostSaveModel. I don't pretend to save the xml file before or during the saving of the SKU file (where obviously the model.path and model.title cannot contain any data) but after the user has saved it. That's why I use the onPostSaveModel.You know you can create a class that is a descendant of the Sketchup::ModelObserver class and override the desired methods, like this one:
class MyModelObserver < Sketchup;;ModelObserver def onPostSaveModel(model) msg = "OnPostSaveModel; \n" + "- Path = '#{model.path}' \n" + "- Title = '#{model.title}' \n" + "- Dir.pwd = '#{Dir.pwd}'" UI.messagebox(msg) end end
When you attach an istance of the MyModelObserver to the model, with:
Sketchup.active_model.add_observer(MyModelObserver.new)
Everytime the SKU file is saved, the onPostSaveModel method is executed.
Here for debugging I'm just checking the model.path value showing it with the messagebox, but in real code I do all the things needed to create the xml data and save it using the model.path (if only it would contain the correct data!)
For the Dir.pwd check for yourself if you dont trust me
Inside the onPostSaveModel method it return the folder where the model has been saved.
But Model.path and Model.title don't.Thanks for all the patience and effort you are putting on helping me.
-
RE: How to get the saved file path
Hi TIG,
I don't think I need the AppObserver, I only need to save the xml file whenever the user save the sketchup file, without disturb him.
Lets see two example where the AppObserver doesn't help.1Β° Scenario: The user create a new file:
The "Sketchup.active_model.path" is an empty string, until is saved. So is useless during the AppObserver "onNewModel" event firing.2Β° scenario: Lets say the user has saved the file, or opened one, so that the "Sketchup.active_model.path" contain his path. But then, if the user decide to use the "Save as" command to save the file to a new location, then I need to save the xml file to the new location, and in this case only the ModelObserver events ("onPreSaveModel", "onSaveModel" and "onPostSaveModel") are fired, not the AppObserver ones.
And if you use the "Sketchup.active_model.path" in the "onPostSaveModel" event, it's not nil nor empty, it contains the old folder and name info!
Note that the word "post" should state that everything involved with the saving action is done, but something still appen after the firing of the event, because when you check again the value of "Sketchup.active_model.path" from the console, it the right one!
So this is definitely a bug, and I hope they will fix it as soon as possible.
I do think that SketchUp is an incredible powerfull program (that I use from version 1.0 !) but IMHO they should revise the full set of observers, and give us (working) pre and post events for all the events. Observers are great, easy to use and a very neat way to extend and personalize SKU, but without pre and post events, many of those are useless at best, and a sure way to crash the program at worst.
The second scenario is also a good answer for your question, i.e. "why do I need to bother with observers": I need to observe the user and take an action (build the xml file and save it with the same name of the SKU file, in the same directory) whenever he save the SKU file.
Meanwhile, I've found that when the user save the file I can find the directory using the standard ruby "Dir" class, with "Dir.pwd" (program working directory) but alas this doesn't help me on regard of the filename that the user has chosen for the SKU file.
-
How to get the saved file path
SketchUp version: 8.0.4811
Operating system: windows 7As I need to save an XML file with the same name of the sketchup file and in the same directory from a ruby script,
I've tried to use the model observer's OnPostSaveModel event, but the model.path is not updated.Let me explain with an example.
Let's say that I create a MyModelObserver class:
class MyModelObserver < Sketchup::ModelObserver
def onPostSaveModel(model)
UI.messagebox("Path = '#{model.path}' ")
end
endand that I attach an istance of this class to the model:
Sketchup.active_model.add_observer(MyModelObserver.new)
Now, if I create a new file from SketchUp and then save it on my desktop as, i.e., "Try1.skp", the message box shows: Path = ''
But after this, opening the console and writing: puts Sketchup.active_model.path
shows the correct info.Conclusion: it seems to me that this is a bug, and I've already filled the bug form, but meanwhile anybody knows a workaround?
-
RE: How to show property value in HTML Description
WOW!
Soo easy I coudnt imagine. Description IS a property, so I can use the equal sign and all the formulas to calculate the value.
Many thanks Jim! -
RE: How to show property value in HTML Description
Thanks everybody for the replies.
@thomthom: Yes, you're right, I'd like to embed a property value inside the HTML of the description, within the context of DC capabilities. So both Dan and Jim proposed solution are not viable.
To answer your question, I can compute a validation error message like (for example):UserParamCheck = IF(OR(Foo < 10, Foo > 300), 1, 0)
ErrorMessage = IF(UserParamCheck,"","Hi, the value of Foo must be between 10 and 300")and (if possible) insert the error message in the HTML.
That way the user will see it only if there is an error, without cluttering the User Interface with a read only property in the input area.
-
How to show property value in HTML Description
Is it possible to reference a property value in the HTML Description of the dinamic component?
Suppose I have a component with two properties visible and editable with two textbox:
LenX
LenYand a third property, not visible:
AreaXY = LenX * LenY
I'd like to have the description property written as (some sort of):
Description = "This is the fabulous Rectangle component<p>You can set LenX and LenY<p>The calculated area, based on your input is ${AreaXY}"
Is it possible?
-
How to use zeroed prefixed string?
Sorry for the silly question, but I can't find the answer elsewhere:
I have a Dinamic Component with this property:
ItemCode = "ID" & CHOOSE(Index,"002","008","020")
The formula always delete the beginning zeros
(i.e. ItemCode returned value is "2" or "8" or "20")I've tried with some workaround (using X instead of zeros and then substitute) without success, but I understand it depends on how text strings are treathed by SketchUp formulas.
Please note that I've setted the property as TEXT (and not default Text)
How can I specify SketchUp formulas not to delete the preceding zeros ?