⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update
  • SU ruby questions part2

    8
    0 Votes
    8 Posts
    1k Views
    Dan RathbunD
    The last error is the result of the quirky implementation of Sketchup::Console class. (It is not a subclass of IO, but should have been.) Try some other way of testing your results. UI.messagebox or a webdialog.
  • Plugin recommended practices

    3
    0 Votes
    3 Posts
    405 Views
    S
    very much appreciated, thanks for the detailed response
  • Dialog box showing counter

    8
    0 Votes
    8 Posts
    906 Views
    D
    @sawdust_online said: Nevertheless I would have liked to save that bunch of files without blocking SU, webdialog box or not. what type of files are you saving? images, components? I think you can you the same approach as the two geometry making versions I posted... @unknownuser said: the following code seems to do the job! what's your take about it ? may it lead to crash ? for a mac it would be better if you used RUBY_PLATFORM =~ /(darwin)/ ? @dlg.show_modal() ; @dlg.show() bring_to_front doesn't achieve the same thing unless it was show_modal before the any focus change... I don't see why you need the timer, any short wait will happen anyway while the file is being written... BTW. sleep(0.25) will work the same as, but looks more like ruby than the fractional floats to me... john
  • Place a shape at regular intervals between two lines

    4
    0 Votes
    4 Posts
    361 Views
    TIGT
    Read up: http://www.sketchup.com/intl/en/developer/docs/classes.php When you add an instance you apply an initial transformation, but you can do more transforming later... A group is a special kind of component. For now let's assume a component existe. So let's assume you have a component-definition containing your 'box' with a reference to it called ' compodef'. Let's assume the references: model = Sketchup_active_model ents = model.active_entities Let's also deal with just one curve, for now... Let's assume you have a reference to just one of the edges that form it, called ' edge'. Let's also assume you'll place instances at its nodes - i.e. the edges' 'end' points. curve = edge.curve vertices = curve.vertices points = [] vertices.each{|v| points << v.position } now you have an array of the points defining the curve. points.each{|point| tran = Geom::Transformation.new(point) instance = ents.add_instance{ compodef, tran } } now you have an instance of the component 'box' located at every node point of the curve... This is a simplified explanation... At least should get you started... If you want to 'swivel' each box to span between the nodes in one curve and the equivalent node in a second curve, then you need to assemble two arrays of points - says points1 and points2 You iterate thus: ` points1.each_with_index{|point1, i| tranp = Geom::Transformation.new(point1) instance = ents.add_instance{ compodef, tranp } length = instance.bounds.length now get the second point point2 = points2[i] dist = point1.distance(point2) scale the box scalex = dist / length trans = Geom::Transformation.scaling(point1, scalex, 1.0, 1.0) instance.transform!(trans) rotate the box vec = point1.vector_to(point2) angle = X_AXIS.angle_between(vec) axis = X_AXIS.cross(vec) ### might be reversed - check ? trana = Geom::Transformation.rotation(point1, axis, angle) instance.transform!(trana) }` this is untested but should give you some ideas... It places the instance scales it so it'll stretch between the two points and the rotates the box so it spans between the two points. Obviously you need to do more work - like making the box component, checking the curve points for 'direction' and count-match etc... Good luck...
  • Sketchup internal matrix transformation error compensation ?

    4
    0 Votes
    4 Posts
    584 Views
    O
    I don't have any code right now, I will once I have access to it though, which should be in a couple of days. The general procedure works like this though. Before anything else, I store the initial orientation by making an axes type Transformation. Something like this if memory serves well : xaxis_ = cInst.transformation.xaxis yaxis_ = cInst.transformation.yaxis zaxis_ = cInst.transformation.zaxis @transform = Geom;;Transformation.axes(Geom;;Point3d.new(0,0,0),Geom;;Vector3d.new(xaxis_.x,xaxis_.y,xaxis_.z),Geom;;Vector3d.new(yaxis_.x,yaxis_.y,yaxis_.z),Geom;;Vector3d.new(zaxis_.x,zaxis_.y,zaxis_.z)) The translations to move to and from the origin are created using the center of the bounds of the component. The origin to object axes are also calculated with an axes type Transformation. I use the inverse to return from global to local. The rotation part of the external transformation is created from an array, with indices 3, 7, 11, 12, 13, 14 set to 0 and index 15 set to 1. Said array comes from extracting numbers from a string. I thought there might be some bug or some accuracy loss here, but it's a double to float conversion on mostly small numbers, and checking the orthogonality of the rotation component gives no error before the 12th digit. The translation part (which is global, not relative to the component, btw) is used to make a vector used to make a Transformation. I've had the skewing even when this was 0, though. And then it goes like this : -Store initial transformation. When transformation is received : -move to origin -switch from object to origin axes -Compensate the initial transformation if there is one. -Apply rotation -apply the inverse of the initial transformation -go to object axes -Apply translation (global) -Move back from the origin Granted, it's not the best workflow. However, given the accuracy I seem to have on the sole matrix that isn't created within SU, I don't understand how the skewing happens, particularly when multiplying all these external matrices together yields an error that is so tiny.
  • Any GOOD dxf writing guides? (Autodesk seems dead)

    4
    0 Votes
    4 Posts
    756 Views
    dereiD
    @tig said: Googling 'dxf reference guide' return lots of interesting hits - e.g. http://www.autodesk.com/techpubs/autocad/acadr14/dxf/dxf_reference.htm Also there are several RB file plugins in the PluginStore which do DXF import/export manipulation - so using those as 'cribs' would help too... So what more do you want ? Thanks for this... i did a lot of search, but I guess I used the wrong keywords ) never found this. Thanks a lot.
  • Load classification system via ruby code

    18
    0 Votes
    18 Posts
    2k Views
    tt_suT
    @blruuska said: Dan, Thanks for verifying. It is surprising that NotImplementedError wasn't raised, if that is the case here. Ackh! Yea, something is amiss here. Not sure if we intended to support enumeration type in the initial release of the API - but if that's the cause it should have been NotImplemented. However, I might confuse this with the "choice" type. Maybe something changed in the last moment. I need to investigate.
  • Adding two Point3d, is that impossible?

    11
    0 Votes
    11 Posts
    1k Views
    Dan RathbunD
    @dan rathbun said: @ziocleto said: The strong typization of Point3d and Vector3d is also very questionable as ... And this why the SketchUp API authors made both classes "compatible" with a basic 3 element array, ... OH.. also.. there is another way they could have gone for this particular method. And that is duck-typing the argument, instead of class-typing it. Ruby example (they are really implemented on the C-side): <span class="syntaxdefault">def </span><span class="syntaxkeyword">+(</span><span class="syntaxdefault">arg</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  raise</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">TypeError</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"invalid&nbsp;argument&nbsp;type"</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">caller</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> unless<br />  </span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> arg</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">respond_to</span><span class="syntaxkeyword">?(;</span><span class="syntaxdefault">x</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&&<br /></span><span class="syntaxdefault">    arg</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">respond_to</span><span class="syntaxkeyword">?(;</span><span class="syntaxdefault">y</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&&<br /></span><span class="syntaxdefault">    arg</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">respond_to</span><span class="syntaxkeyword">?(;</span><span class="syntaxdefault">z</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">||<br /></span><span class="syntaxdefault">  </span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> arg</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">respond_to</span><span class="syntaxkeyword">?(;[])</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># be sure it has 3 members<br /></span><span class="syntaxdefault">    arg</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Numeric</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> rescue false </span><span class="syntaxkeyword">&&<br /></span><span class="syntaxdefault">    arg</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Numeric</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> rescue false </span><span class="syntaxkeyword">&&<br /></span><span class="syntaxdefault">    arg</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">2</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Numeric</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> rescue false </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    </span><span class="syntaxcomment"># rescue modifiers trap IndexError exceptions<br /><br /></span><span class="syntaxdefault">  </span><span class="syntaxcomment"># the method body<br /><br /></span><span class="syntaxdefault">end</span> If you are only concerned with Ruby 2.0+, then you can use a refinement module to correct the method for you code only.
  • Deleting an Edge knowing 2 points

    4
    0 Votes
    4 Posts
    397 Views
    K
    Thanks TIG and Dan I applied the code to the Tails part of my Dovetail Tool and now the result is a part with tails that is still a solid. No left over edges or faces. The strange thing was that when selecting the component edges if you selected them clockwise (edge1 to edge2) the part was clean but selecting in a counter clockwise direction there were left over faces. Now thanks to your help edge selection direction works either way. Thanks Keith
  • Fails succeeds fails......

    6
    0 Votes
    6 Posts
    472 Views
    sdmitchS
    @tig said: I don't have time to dissect your code in detail... But it seems to me you are replicating my Latticeizer plugin ? Look at that... http://sketchucation.com/pluginstore?pln=Latticeizer You need to offset the perimeters of the edges' faces [which sometimes fails, just like native-offset - so it perhaps needs my Smart_Offset?] It's NOT easy... Don't waste your time dissecting it since this is a just for fun exercise. I have found a number of bugs but have a few more to go. I have no intention of publishing it since, as you say, there is Latticeizer and others already out there.
  • Return values from ruby system calls

    3
    0 Votes
    3 Posts
    601 Views
    Dan RathbunD
    SketchUp 2014 was bugged in this regard. The workaround was to pipe to a text file, I think. I think it was fixed in SketchUp 2015. I recall having written a patch script that overrode the Kernel.backquote method. (I have to have a look for it.)
  • Load a vismat / vray material into sketchup??

    2
    0 Votes
    2 Posts
    422 Views
    Dan RathbunD
    A good question for: http://forums.chaosgroup.com/
  • Textures in model slow down ruby?

    10
    0 Votes
    10 Posts
    668 Views
    Dan RathbunD
    @wawmsey7 said: However it would be easier if I could have code before the code for loading the component to check if it's already loaded or not into the model and then load it if it's not already there? Is that do-able? You need to search the DefinitionList collection properly. This class, like many of the API collection classes, has the Enumerable library module mixed in. The following method should be wrapped within your plugin module: def self.get_component( filepath = "some/path/to/component.skp" ) # Warning, on MS Windows the definition paths are # returned with backslashes not forward slashes ! filepath = filepath.tr("\\",'/') dlist = Sketchup.active_model.definitions found = dlist.find {|cdef| if cdef.path.nil? false elsif cdef.path.tr("\\",'/') == filepath true else false end } return found if found if File.exist?(filepath) dlist.load(filepath) else return false end end
  • State of Observers ?

    2
    0 Votes
    2 Posts
    345 Views
    Dan RathbunD
    @oajfh said: ...Tool Observer (OnButtonUp and OnButtonDown) ... There is not a ToolObserver class in the API. The onButton.. callbacks are part of the abstract Tool class, not an observer class. @oajfh said: ... and an EntityObserver (OnEntityChange), ... Write a quick test observer and see if it fires when you move an object. @oajfh said: Does this seem like the most natural way to you ? Are there any latent bugs (seems like Observers have had problems in past versions, I can't seem to find more recent information) or potential problems to this approach (I've read up on a few common pitfalls but don't know much more) ? Welcome the foggy world of SketchUp API Dcoumentation. Where nothing is really certain, and all are kept in limbo.
  • [Suggestion] Web Exporter 2?

    15
    0 Votes
    15 Posts
    2k Views
    A
    hello all, i'm looking for a plugin or extension that make rotation of the object, for example any 15 degrees each, to create sprites for games or visualization. i've found web exporter beta but i'm not able to found the download link, no in extension warehouse nor plugin store. please let me some suggestions! many thanks Akira
  • Associating data structures with save

    11
    0 Votes
    11 Posts
    861 Views
    Dan RathbunD
    @devinlange said: At the very least if the user modifies the faces I don't want anything to fail. This will be difficult. As faces get modified, or new edges intersect with them, they get split up into multiple faces, and sometimes get new object ids. Myself, I'd never rely on "setting" a path of primitives, and expecting the path of them to survive. Instead I'd create a virtual path. Could be a series of Guidelines (Construction lines) in a special group. Or actually maybe a Curve (which is SketchUp's name for a series of edges connected end to end,) within a group context, and on a "path" layer that can be turned off. The path and it's group can also be locked. You could associate the vertices of the path with one of the vertices of a face. Later on when you need to "follow the path" you iterate the Curve's collection of vertices, and use a PickHelper object to find the face under the current vertex. Push the face reference into an array, and repeat. Just thinking out loud.
  • Detect if cpoint is clicked

    6
    0 Votes
    6 Posts
    490 Views
    Dan RathbunD
    @maricanis said: I was concerned what would happen if user select other Scene for example while tool is active, ... I believe the active_view is a singleton object of the model. (there is only one.) The user sees scene pages through the active_view.
  • Revert back to saved version

    8
    0 Votes
    8 Posts
    4k Views
    TIGT
    Going back several steps .move! works like .transform! without affecting the stack within an animation ?
  • Vertex Normals... ?

    26
    0 Votes
    26 Posts
    3k Views
    Dan RathbunD
    @oajfh said: Sorry for dragging this topic on for so long. Don't worry about it. This is the kind of nitty-gritty dirty details us consummate geeks really love to ponder.
  • Best practice for followme

    2
    0 Votes
    2 Posts
    322 Views
    sdmitchS
    Put the face in a group the do the followme. Everything created by the followme will be added to that group myGroup = Sketchup.active_model.entities.add_group myFace status = myFace.followme(lines) Then you can move the group.

Advertisement