Boom! That worked!
Thank you sir!
--J
When I create a component via .add_group and then .to_component, the component axes are set to the lower left extremities. Meanwhile, making a component via the Edit menu, I can specify the Component Axes in the dialog.
How can I set or move the component axes when I create the definition via Ruby?
Many thanks for any assistance!
--J
Okay, so it is just a permissions issue, browsers don't allow loading a local image from a remote page.
So in terms of feeding the image to the dialog, I'm not having success. Here is what I have, which is not working:
require "base64"
jpg = "/path_to_image/fancy_image.jpg"
s = File.binread(jpg)
b = Base64.encode64(s)
@dialog.execute_script("document.getElementById('preview').src='data;image/jpg;base64, #{b}'")
I'm sure I screwed up something simple, thanks helping me to find out what!
--J
To recap, moved an HTML page from living in its plugin folder, to living on our web server.
Everything with it is working fine, except for setting the image source to a local jpg.
It does need to be dynamically set.
When I inspect it, the image SRC is set, the image is just not displaying.
Thanks for the tip on base64, it's looking like I'll need to go that route.
--J
I have a web dialog that is being migrated from local html to being remotely hosted.
The only part that is not working, is the setting of the image source. It must be some sort of permissions issue I figure.
I am firing something like:
d.execute_script("document.getElementById('#{myimg}').src='file:///path/image.jpg'")
Which works fine if the html is local!
If this is some security built into the Safari web dialog engine.... Do I have to feed the image as a binary string?
Many thanks for any help!
--J
It looks like the version on Sketchucation is not the latest.
Please download the latest one here:
http://www.landfx.com/index.php/kb/installation/item/646-how-to-install-the-sketchup-plugin.html
We just shot an hour long webinar showing off what the plugin can do. It will be posted here, no later than Monday, January 27:
http://www.landfx.com/index.php/videos/webinars.html
Lastly, we are also in the process of updating the documentation for, available here:
http://www.landfx.com/index.php/land-f-x/sketchup-connection.html
You're also always welcome to contact us directly, at http://www.landfx.com/support
--J
Actually, it does just seem to be exactly that, allow_actions_from_host.
I had noticed with V6 that it was ignored, so I never implemented it.
But in my remote WebDialog, which is failing, I simply add an allow_actions_from_host, and suddenly now it's working again.
--J
I can give you a quick example to one that isn't working if you need.
--J
Here's a little more info from testing if this helps.
I have two dialogs which are identical, both just a Select listbox, with an OnChange event that fires a window.location callback. Using Transitional doctype.
The one that is a local htm file stored in the Plugins folder, that works.
The one that is remote PHP, that one fails.
--J
Everything totally broken here.
Tried changing the Doctype around, from Transitional to Strict to Html 5, all no change.
Tried href= vs window.location= vs document.location=, all broken, broken, broken.
If TIG or anyone has sample code that does work within Mavericks, I'd love to see it.
Most of our skp: callbacks are within Javascript for ease of maintenance. Usually fired by onclicks, but it can vary.
--J
I personally felt the license agreement, and more so the language on the web site and download links, was always quite clear regarding commercial use. But more-so, I do agree with you, that it is a rather unfortunate change of course. My biggest fear, is that it will destroy the bulk of the creative efforts going into the 3D Warehouse. I personally get a great thrill out of downloading various space ships and crazy vehicle creations -- almost certainly the efforts of a 14 year-old boy somewhere out there on the internets. And there's no way they will be plopping down $500 to continue such endeavors.
So if I may, I'd like to offer my suggestion -- perhaps a $199 price point for Make? Or go even further, and offer something integrated with the 3D Warehouse -- so as long as you upload at least 1 model a month to the Warehouse, you can continue using Make for free.
More on the subject of your post, I feel it was a little naive of you to pursue a commercial business model off of the free software that Google was offering. I would recommend you stay with Sketchup, and contact their bulk sales department, to see if you could get some funding, and negotiate a good price to continue what sounds like an otherwise great business model.
--J
Perhaps start with something like this:
http://zetcode.com/db/sqliteruby/
--J
If your data needs are truly that simple, then you definitely don't need MySQL.
Consider that to even install MySQL now, users would have to navigate their web site, find the right installer, follow a rather complicated install process... This is just madness, if you are just trying to save a few coordinates.
Better solutions would be to save as XML or similar text file, with Sketchup.write_default, or with a WebDialog that accesses your remote MySQL data through PHP.
Having a local structured query language is of course handy, but since you're not talking multi-user, if you were to integrate something, go with SQLite, which is intended for exactly this scenario.
--J
Just a slight misunderstanding, but I wasn't totally clear.
I want to be able to place a component like a bench, and then immediately rotate it about the Z axis.
So both the placement and the rotation should be linked very smoothly to accurate cursor position.
My use of the 15.degrees was just a placeholder, that was actually what I wanted to derive, the angle from the component's insertion point, to the current cursor position.
So I was after a sort of rubber-band style rotation, basically like the Rotate tool. Yours is more of a wheel style, bumping it 15 degrees each time you nudge the mouse. That has its value too, so it's nice to have in the tool basket.
Thanks for the help!
--J
Ah, I see what you were saying TIG.
Like this:
crossvector = vector.cross(X_AXIS)
multiplier = crossvector[2]
if (multiplier < 0)
multiplier = 1
else
multiplier = -1
end # if
# so now our angle is
fangle = X_AXIS.angle_between(vector)
fangle = fangle * multiplier
No understanding of why that works, but if you say so, then it's the way to do it!
Thanks for help, you rock!
--J
Ah! I'm getting there!
So now I just need to convert angle_between to true angle. Would that be un-normalizing it? Do something with the vectors and compare their reverses or something... hmm...
Improved mousemove:
def onMouseMove(flags, x, y, view)
# we toggle visibility while picking the point, so it doesn't interfere
@comp.visible = false
@ip.pick(view, x, y)
@comp.visible = true
ptx = Geom;;Point3d.new(@ip.position)
if ( @rotate ) # then we are just rotating about @p0
myz = @comp.transformation.zaxis # axis we are rotating about
ptx = Geom;;Point3d.new([ptx.x,ptx.y,@p0.z]) keep at same Z
vector = @p0.vector_to(ptx) # vector from component insertion to mousepoint at same Z
fangle = X_AXIS.angle_between(vector) # angle (but only up to 180!)
# but how do I determine if it is that, or -1 * that?
@comp.transformation = Geom;;Transformation.new(@p0) # if i don't do this first, it goes to 0,0
@comp.transform! Geom;;Transformation.rotation(@p0,myz,fangle)
else # placing
@comp.transformation = Geom;;Transformation.scaling(@scalex,@scalex,@scalex)
@comp.transform! Geom;;Transformation.new(ptx)
@p0 = ptx # save last point
end # if
end # onMouseMove
Ugh, still no luck.
Among my issues -- I added a test of creating an edge, just to see what my "target" point was.
By still keeping the .pick method in there, it just keeps "vibrating", jumping around like mad -- I'm not clear on what to test for, whether the ip.pick is too far away -- maybe if the angle calculated is more than, say, 45 degrees from what it is currently?
But then going off of just the x,y from the mousemove, that seems off too, not sure what's wrong with that.
And then the other problem is that the angle_between is always less than 180 degrees, so I guess I do need to use .cross or something, but at a loss for how.
So here's what I have so far, absolutely grateful for any assistance!
class PlaceandRotate
def initialize
@model = Sketchup.active_model
@p0 = nil # point about which we rotate site
@rotate = nil # if we are rotating site
@compdef = @model.definitions[0] # component to be placed
@comp = nil # our guy we will be placing
@ip = nil # input point
end # intialize
# activate event fires upon tool usage
# load component at 0,0, prep data input points
def activate
pt0 = Geom;;Point3d.new([0,0,0])
@comp = @model.entities.add_instance(@compdef,pt0)
@ip = Sketchup;;InputPoint.new
end # activate
# as user moves mouse, we apply a transformation to the component.
def onMouseMove(flags, x, y, view)
if ( @rotate ) # then we are just rotating site about @p0
myx = @comp.transformation.xaxis # current xaxis
myz = @comp.transformation.zaxis
# this is not working, yet i don't want to have to do an ip.pick here, as it picks up too much clutter
# but going off of just x,y is off, not sure how i need to apply view vector or what
p00 = [x,y,@p0.z] # mouse position, at same Z as component origin
vector = @p0.vector_to(p00) # vector from origin to mouse position on same Z
# draw a test edge to confirm our p00 is good
@model.entities.add_edges [@p0,p00] # test edge to see if it is
# at least all the test edges are correctly on the Z plane!
fangle = myx.angle_between(vector) # but only goes up to 180.
# need to use V.cross to determine true angle?
@comp.transformation = Geom;;Transformation.new(@p0) # reapply our point
@comp.transform! Geom;;Transformation.new(@p0,myz,fangle) # rotation
# if we instead just do .transformation = .new(@p0,myz,fangle), it goes to 0,0
else # placing
# turn off our guy so we don't confuse him with .pick
@comp.visible = false
# infer our mouse point
@ip.pick(view, x, y)
ptx = Geom;;Point3d.new(@ip.position)
# after picking a clean point without component in the way, turn him back on
@comp.visible = true
@comp.transformation = Geom;;Transformation.new(ptx)
@p0 = ptx # save last point for when rotating
end # if
end # onMouseMove
# L button click, switch to rotating, or place and loop
def onLButtonUp(flags, x, y, view)
if (!@rotate) # switch to rotating
@rotate = true
else # then we are placing again!
@model.select_tool PlaceandRotate.new
end # if
end # onLbuttonup
# user pressed Esc, erase current plant and exit
def onCancel(reason, view)
# erase component
@model.entities.erase_entities @comp
@model.select_tool nil
end # onCancel
end # PlaceandRotate class
def pandr
Sketchup.active_model.select_tool PlaceandRotate.new
end # def
I've looked through a bunch of previous posts, but just can't find quite what I need.
I have a custom tool that helps in placing parts.
After clicking for the insertion, I'd like it to rotate the component about its insertion point, relative to Z axis, in relation to where the mouse is.
So within my onMouseMove, moving it around is easy enough, inputpoint.pick, and then @comp.transform!(Geom::Transformation.new(ptx)).
So then the user clicks the mouse button, and now the relevant onMouseMove should be applying a rotation, as per the component insertion point (@p0), and the current mouse point (ptx), about the Z axis.
But I'll be darned if I'm having a heck of time doing that!
I mean, I can do this:
@comp.transform!(Geom::Transformation.new(@p0,Z_AXIS,15.degrees))
but that just applies 15 more degrees of rotation to the component, so no matter where you have the mouse, just as you move it, the table just keeps slowly rotating.
So I'm struggling with creating a vector to the new point, ptx, yes? And then I should be able to determine the angle of that vector? And then, its transformation= instead of transform! ?
Hoping that is clear enough? I can clean up the code and post if you need.
Thanks, as always, you guys keep saving my rear!
--J
I've tried a few variations now.
added a BoundingBox intersection testing, and if that hits, then do an intersect_line_line.
That ends up taking about 10% more time.
Then on a whim, I even removed the Vector checking, that saves time.
So no matter what I try, indeed, it seems the fastest is to get to the intersect_line_line as quickly as possible, as that's even faster than comparing the vectors first.
The really unfortunate part, now, is that I've found in trying to add a progress bar at the status line, that just seems to add a huge amount of time to the operation. I'd rather have a spinning pinwheel for 30 seconds than a progress bar for 2 minutes. I guess I could try optimizing the progress bar function, it looks like it's updating the status bar text every iteration, regardless of whether the percentage has changed.
Thanks as always for the tips!
--J
Sorry, guess I wasn't clear.
I have the pointonline function, and yes, that's easy, hence why I didn't bother including it.
My issue, is that in a model with 1,500 edges, the afore posted routine takes over 30 seconds to complete.
What I was hoping to do, was to optimize that routine if possible. As near as I can tell, I have to iterate through all edges, and compare each to all other edges, perform an intersect_line_line, and then check if that point falls on both edges. Correct?
I tried adding some basic coordinate validation, checking the X and Y coordinates of each edge end point first, to see if an intersection might be possible, but just took even more processing time.
I'm about to check the exact processing hit for each of the key tests, to see what is the big hangup, but thought I'd post what I have so far to see if there's any thing that jumps out as slow.
--J