Quantcast
Channel: Ruby API - SketchUp Community
Viewing all 3017 articles
Browse latest View live

Hiding Lines

$
0
0

@medeek wrote:

I’m sure this topic has probably been covered before and I am quite certain that Christina Eneroth has a plugin that specifically deals with this issue in a somewhat related manner.

If you look at the 2D model below you can see the separate wall segments.

I am trying to figure out a way to hide the line segments between each wall panel so that the end result is what you would more typically see for a floor plan layout.

I suppose one way to do it would be to pushpull all of the segments then union them together into one solid and then delete everything except the bottom face of the wall solid leaving just the single face.

Posts: 4

Participants: 4

Read full topic


Exit a Tool with ESC Key

$
0
0

@medeek wrote:

I would like to make it possible to exit any of my tools with the ESC key (Escape). Does anyone have an example or know how to do that?

I find this feature very handy within other drafting programs, and it would increase the speed with which you could use the plugin.

Posts: 9

Participants: 3

Read full topic

Bounding Box Contains?

$
0
0

@medeek wrote:

I’m trying to use the contains? method for bounding boxes and I am comparing one bounding box to another. I’m assuming for the boolean to be true that the bounding box you are checking on must be fully inside the other one and not just touching it.

Posts: 1

Participants: 1

Read full topic

Selecting Groups by Name

$
0
0

@medeek wrote:

I’m trying to grab all of the top level groups that have the follow text in their instance name: WALL_ASSEMBLY_

My original line of code is giving me errors since it is also picks up any random lines or other geometry drawn and then it is throwing an error since the name parameter does not exist for some of these entities.

My code is:

# Gets all Wall Assemblies

	wall_list = Sketchup.active_model.entities.find_all { |e| e.name =~ /_WALL_ASSEMBLY_/ }

Posts: 9

Participants: 4

Read full topic

Self.reset vs. reset

$
0
0

@medeek wrote:

I’ve noticed in the various sample tools that I’ve been studying that in some of the methods reset is called out instead of self.reset, is there a particular reason for this?

Posts: 4

Participants: 3

Read full topic

Detecting Deleted Entities

$
0
0

@medeek wrote:

In one of my tools I’ve created a list of entities (groups), after an action by the user there exist the possibility of one or more of these entities being deleted and within the list this appears in its/their stead:

<Deleted Entity:0x17971b68>

or the list:

[#<Deleted Entity:0x17971b68>, #<Deleted Entity:0x17971bb8>, #<Deleted Entity:0x17971b90>]

Is there a simple way to detect this deleted state of the entity as I am looping through this list?

Posts: 4

Participants: 2

Read full topic

Code a SketchUp layer/scene script with Ruby!

$
0
0

@RafaelRivera wrote:

LayerScene: Learning how to write a SketchUp script by example.

Untitled-1|640x3,60

In this tutorial we’re writing a #SketchUp script that will automatically create scenes with the names of every layer in your model. The best part is that entities which belong to a specific layer will only be visible in the scene that matches that layer’s name.

The instructions on how to run the script with the Ruby Code Editor Plugin is in my first tutorial.

But, If you like LayerScene and want to install it as a SketchUp Extension/Plugin which includes a toolbar button, then you can buy it for a small fee Here.

➜ Read the Full Tutorial Here


Note: This tutorial is targeted towards beginners so the pros may not gain as much value. However, you can still help me out if you spot an error or a better way to write the script. Cheers!

Posts: 1

Participants: 1

Read full topic

[FR] ONLY load extensions from the users personal folder

$
0
0

@eneroth3 wrote:

Right now I cannot start SketchUp at all at my university. A load error in V-Ray (which I am not even planning to use today) causes SketchUp to bugsplat. I can’t even get to the point where I can open the Ruby Console and disable plugin loading or open the Extension manager and disable V-Ray.

Uninstalling the plugin is impossible too as it is installed to ‘C:\ProgramData\SketchUp\SketchUp 2018\SketchUp\Plugins’ where I don’t have write permission. Instead I have to wait for the system administrators to fix the error which perhaps takes days.

Please make it so SketchUp doesn’t load Ruby plugins from any folder except the personal plugin folder. The plugins can very well be installed in a shared folder, but the loader script must be within the users grasp.

Posts: 5

Participants: 2

Read full topic


Redo observer does not send on modified/on change events

$
0
0

@ErikRoss wrote:

Hi there, I’m making an extension that observes the model’s changes. I’ve noticed that for certain actions, onChangeEntity (from EntityObserver) and onElementModified (fromEntitiesObserver) are not fired when the action is done with a REDO. Recreate the issue with the following:

  1. Create a rectangle.

  2. Select the face only of the rectangle.

  3. Run the following code in the Ruby console.

    class MyEntityObserver < Sketchup::EntityObserver
    def onChangeEntity(entity)
    puts “onChangeEntity: #{entity}”
    end
    end

    class MyModelObserver < Sketchup::ModelObserver
    def onTransactionCommit(model)
    puts “Transaction committed.”;
    end
    def onTransactionUndo(model)
    puts “Transaction undone.”;
    end
    def onTransactionRedo(model)
    puts “Transaction redone.”;
    end
    end

    model = Sketchup.active_model
    entity = model.selection[0]
    entity.add_observer(MyEntityObserver.new)
    Sketchup.active_model.add_observer(MyModelObserver.new);

  4. Move the rectangle face around several times. Note in the console the onChanged event is fired.

  5. Undo your movements. The event is still fired.

  6. Redo the movements. The event is no longer fired.

Is there a reason for this behaviour, or is it a bug? I’m trying to think of a workaround, but this seems like a pretty tough problem to resolve. Is there any other way to observe when an entity is modified, no matter what? Or pull the undo stack from Sketchup itself?

Thanks for any help,
Erik

Posts: 1

Participants: 1

Read full topic

Applying a material to a specific Face within a Group

$
0
0

@medeek wrote:

I have a very simple solid, a cylinder (ie. a threaded rod). I typically just apply a material to an entire group to get the effect I am looking for but in this case I would like to apply a specific material just to the face(s) that wrap around the cylinder and then at the group level I will apply my default material as normal.

Is there an easy way or algorithm to somehow grab this cylindrical face? I don’t think I’ve tried this one before since I usually apply threads to pre-configured components manually and then later load them into the model via the API.

Posts: 4

Participants: 3

Read full topic

Loading components from a File

$
0
0

@medeek wrote:

With this wall plugin I am loading more third party components from a file than ever before. My tried and true load method is the following:

def load_holdown_hardware (holdowntype)

	model = Sketchup.active_model()
	definitions = model.definitions

	this_dir=File.dirname(__FILE__)
	# Fix for ruby 2.0
	if this_dir.respond_to?(:force_encoding)
		this_dir=this_dir.dup.force_encoding("UTF-8")
	end

	filename1 = File.join(this_dir,"components/#{holdowntype}.skp")		
  	@hd_componentdefinition = definitions.load(filename1)

end

The plugin rebuilds the entire wall panel and tries to reload any components it need with every edit. I am wondering if there is penalty for reloading a component if it already exists in the model (should I be check for this) or does SketchUp essentially check for you and if its already loaded it ignores the command? This is what it appears to doing since older versions of the component do not seem to be overwritten with new ones once they are already present.

Posts: 1

Participants: 1

Read full topic

Interpolation problem when sending strings to HtmlDialog via execute_script()

$
0
0

@hank wrote:

Hello All,

when I call

@d.execute_script("document.getElementById('body').innerHTML = 'hey';")

it works. But when I call

@d.execute_script("document.getElementById('body').innerHTML = '#{@body}';")

I get an error in the DevTools console:

Uncaught SyntaxError: Invalid or unexpected token

I think it has something to do with my string @body which, when I print to the Ruby console looks perfect like this:

<div>
<label>trim_width</label>
<div id='trim_width'>3.5</div>
</div>

Same thing if I simplify my @body string to something like “hey”

I tried ThomThom’s suggestions using .inspect and even %{} to no avail.

Posts: 4

Participants: 3

Read full topic

Global Variable?

$
0
0

@medeek wrote:

I’ve never used true global variables in Ruby because the SketchUp team have helped me steer away from that (ie. $somevar) possible disaster.

However I would like to make a variable accessible across two different modules:

module Medeek_Engineering_Inc_Extensions::MedeekWallPlugin::Settings

  class MedeekMethods
  	class << self

and here:

module Medeek_Engineering_Inc_Extensions::MedeekWallPlugin::Wall

  class MedeekMethods
  	class << self

What is the suggested way to handle this?

Posts: 13

Participants: 5

Read full topic

Secrets revealed on how to register a SketchUp extension with toolbar button and menu item

$
0
0

@RafaelRivera wrote:

Blog Tutorial on Herosu.com

We are learning how to register our script as an extension so it can automatically load every time we start SketchUp. We also want to create a toolbar button and a menu item for activating our extension.

I am going to provide you with a template for you to download and use as a base for your extension.

➜ Read the Full Tutorial Here

Posts: 1

Participants: 1

Read full topic

Getting zoom level for parellel projection camera?

$
0
0

@Mickael wrote:

Hello !

I am trying to get the camera position (the eye) in the 3D model, which has been set manually. Thing is, since most of my cameras are parallel cameras, the zoom level make the camera eye position irrelevant.
So, I am looking for a way to get this zoom factor of the current view, so I could hopefully retrieve the camera / view position within the scene. But the zoom function from the View class doesn’t seem to return any value.

Am I missing something here ? Any idea about how to do that ?

Posts: 3

Participants: 2

Read full topic


Overlapping Group Check

$
0
0

@kharr wrote:

Hello all.
I’m fairly new to the extension development, and I’m running into a road block… I have a ruby script that trims a group A (solid) based on another group B (solid), which works great.

My question is, how can I limit or stop the trim from occurring if group A overlaps say a group C? I’m looking for an if statement check prior to trim.

Thanks for the help.

Posts: 2

Participants: 2

Read full topic

Hiding Entities

$
0
0

@medeek wrote:

I just tried applying the .hidden method to an array of entities, which it did not like. I’m assuming that I will need to loop through the array and hide each entity but I wanted to check here first if possibly I was missing something.

Posts: 4

Participants: 2

Read full topic

Finding a point on an edge

$
0
0

@medeek wrote:

I’ve searched the forum and I can’t seem to find this topicso I will revisit it again.

I’ve got a 3D point and I would like to check if it is on a edge defined by two verticies. I am familiar with the on_line? method however this is not precise enough for me since the point may actually fall on the line in space but not actually be between the two endpoints.

I can’t seem to find a method to do this check but I might be missing something so again I bring the question to the forum.

Posts: 2

Participants: 1

Read full topic

MyEntitiesObserver crashes SketchUp on mac!

$
0
0

@dynamiqueagencement wrote:

As the title says, I have the bad surprise to discover that MyEntitiesObserver crashes on mac while it works very well on pc.

Here is a simple example:

class MyEntitiesObserver < Sketchup::EntitiesObserver
  def onElementAdded(entities, entity)
    return unless entity.is_a?(Sketchup::ComponentInstance)
    entity.model.start_operation('add texture', true, false, true)
    $dc_observers.get_latest_class.redraw_with_undo(entity)
    entity.model.commit_operation
    entities.remove_observer(self)
  end
end
Sketchup.active_model.entities.add_observer(MyEntitiesObserver.new)

Just import a component with multiple nested entities to crash SketchUp on mac.

The bute is to redraw the next dynamic components inserted in SketchUp.

Is there another solution that MyEntitiesObserver that works on mac?

Thank you in advance for your help.

David

Posts: 3

Participants: 3

Read full topic

Scripting Dynamic Components

$
0
0

@medeek wrote:

I haven’t done a lot with dynamic components but I’ve recently been thinking it would be nice to have a dynamic component with certain parameters or variables that one could signal from within a plugin.

I guess my question is, is there a way to script a dynamic component or interact with one. For instance I have a specific component that I would like to control the height dimension (ie. push-pull). Could I pass it a length and it then automatically adjust?

Posts: 5

Participants: 2

Read full topic

Viewing all 3017 articles
Browse latest View live