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

Object highlighting under the cursor like in Joint Push Pull

$
0
0

@bakursky wrote:

Hi, everybody! I want to create a plugin which can fix a tiny UX problem in SketchUp - edge and face highlighting when mouse on. Any modern 3d modeling tool has this feature. I’ve found this feature in Joint Push Pull plugin, but I want to do it by default in SketchUp startup. Can you help me with some code?

Posts: 4

Participants: 3

Read full topic


Learning How to License My Extensions and Need Help

$
0
0

@RafaelRivera wrote:

Continuing the discussion from Licensing errors passing undetected:

The update has been released and I managed to successfully test the Temporary License feature. But, I have the following questions.

When I test the Trial License it puts “The license will expire in 2 days.” with the following code…


ext_id = "40404040404040404040404040404040404" # Fake id...
license = Sketchup::Licensing.get_extension_license(ext_id)  
 
if license.days_remaining != 0
  puts "The license will expire in #{license.days_remaining} days."
end

# returns "The license will expire in 2 days."

Questions so far…

  1. Why is the trial license test outputs 2 days remaining and how can we set the time period ourselves?
  2. How to download the Plugin from Extension Warehouse without spending money?
  3. How does the trial license work exactly…Do I create a separate extension with a Free to download page that directs people to the paid Extension page once the trial expires?

Thanks in Advance :smiley:



Here is all the Code I am using for the License...
ext_id = "40404040404040404040404040404040404040404" # Fake id...
license = Sketchup::Licensing.get_extension_license(ext_id)
unless license.licensed?
  # The following 'dialog'  was suggested by eneroth3
  msg = "Extension isn't licensed. \n\n Do you want to open the Extension Warehouse to get a license?"

  if UI.messagebox(msg, MB_YESNO) == IDYES
    ew_identifier = "iselect-0"
    html = <<-HTML
    <a href="skp:launchEW@#{ew_identifier}">Show in Extension Warehouse</a>
    <script type="text/javascript">document.getElementsByTagName('a')[0].click()</script>
    HTML
    dlg = UI::WebDialog.new("iSelect", true, nil, 0, 0, 100_000, 0, true)
    dlg.set_html(html)
    dlg.show
  end
  Sketchup.send_action('selectSelectionTool:')
  return
end

if license.days_remaining != 0
  # Thinking of what to put here...
  puts "The license will expire in #{license.days_remaining} days."
end

if license.state == Sketchup::Licensing::TRIAL_EXPIRED
  # Thinking of what to put here...
  puts "Trial period has expired."
end

Posts: 2

Participants: 1

Read full topic

Negative Indexing into InstancePath

$
0
0

@orestes211 wrote:

I noticed that you cannot index into an InstancePath using negative indices like you can for a normal array. Also I’ve noticed that using the leaf property of the InstancePath doesn’t yield anything if the last object in the InstancePath is a Group or ComponentInstance.

I’m not sure if these are expected behaviors and these should be feature requests or if they are bugs.

Posts: 7

Participants: 5

Read full topic

Undo operations and Entity references

$
0
0

@TommyK wrote:

I have a problem with my plugin and Undo operations. I have a set of custom classes which store collections of Sketchup entities. These all react to observer events of various kinds.

I have discovered that when a user hits “undo”, the references I have in my custom classes to these entities become Deleted Entity references.

Try this for yourself in the Ruby console:

  1. create a rectangle, and select the face, type temp_face = Sketchup.active_model.selection[0] into the console
  2. move one of the edges of the face. You will find that typing puts temp_face into the console will refer to the same face.
  3. now hit “Undo” form the Edit menu.
  4. type in puts temp_faceto the console again, and you will find that it refers now to a Deleted Entity.
  5. Try “Redo” and you will find that the temp_face still refers to a Deleted Entity.

All this makes it very difficult for me to track entities (which I observe with various observers) across the undo stack. In fact when the user clicks “Undo”, pretty much my whole custom entities structure gets broken.

Is there anything I can do to continue to track entities across Undo commands, or do I have to rebuild my custom classes (and observers) on every Undo (and Redo) operation? Sounds expensive to me.

Posts: 1

Participants: 1

Read full topic

SU2019 - Ruby version poll, and stand-alone Ruby poll

$
0
0

@MSP_Greg wrote:

What version of Ruby would you like to see included with SketchUp 2019?

  • 2.2
  • 2.3
  • 2.4
  • 2.5
  • 2.6
  • Any of the above or no opinion

0 voters

Notes:

  1. A list of current Windows builds is shown at MSP-Greg/appveyor-ruby, a current list of Travis MacOS builds is shown at MSP-Greg/travis-ruby.
  2. Note that both Windows & Travis use OpenSSL 1.1.0 from Ruby version 2.5 forward.
  3. If you have a preference for a specific teeny version (other than the most current), please state reasons. Ruby versions are MAJOR.MINOR.TEENY

Do you use stand-alone Ruby, and if so, how often?

  • Never
  • A few times a month
  • A few times a week
  • Daily

0 voters

Thanks, Greg

Posts: 2

Participants: 2

Read full topic

Oauth Webdialog VS HTMLDialog

$
0
0

@denis_bolomier wrote:

Hi All,

I have a html page that starting by an Authentification base on Google Oauth ( gem devise)

With Chrone, IE or Safari on PC and Mac, my login work.
When I use Webdialog inside Sketchup PRO 2016,2017,2018 on Mac and PC, authentification, work .
but if I use Htmldialog on mc and pc on Sketchup Pro 2018, redirection of Oauth doesn’t work.

1 - the landing page is Display

2 - after clicking on login , a withe page is display without any information:

Normaly this login page should be display

Console of HTMLDIALOG Doesn’t show error ?
It’s like redirection and turbolink doesn’t work with HTMLdialog.

Find below the code of the webdialog that works

		$wcui = UI::WebDialog.new(title, true ,title, 950, 850, 10, 10, true)
		$wcui.navigation_buttons_enabled = true
        url = @options[:serverUrl]
		$wcui.set_url url
		$wcui.allow_actions_from_host(@options[:serverUrl])
		$wcui.show
		@string_from_wcui =""
		@current_index = 0

The code of the HTML DIALOG That doesn’t work

        url = @options[:serverUrl]
		$wcui = UI::HtmlDialog.new(
		{
		  :dialog_title => title,
		  :preferences_key => "com.sample.plugin",
		  :scrollable => true,
		  :resizable => true,
		  :width => 950,
		  :height => 850,
		  :left => 10,
		  :top => 10,
		  :min_width => 50,
		  :min_height => 50,
		  :max_width =>1000,
		  :max_height => 1000,
		  :style => UI::HtmlDialog::STYLE_WINDOW
		})
		$wcui.set_url url
		$wcui.show

Thanks for your help.

Posts: 3

Participants: 3

Read full topic

Sketchup.write_default location in SU2018

$
0
0

@Tomasz wrote:

I cannot find setting being saved in the registry on Windows with write_default.
Where is the data stored? I have to debug it/delete the key.

The documentation says nothing about changed location.

Posts: 2

Participants: 1

Read full topic

UI.openpanel returns no slashes

$
0
0

@dudenas wrote:

Hi community,
I’m new to ruby, so probably it’s something basic.

I’m trying to get a variable containing just a folder path via UI.openpanel.
There seems to be no option to select a folder, so I’m asking users to select any file in the folder, so that in the next step I can just remove filename from it (ugh).

imglocation = UI.openpanel("Choose any image from images folder", "/", "Image Files|*.jpg;*.png;||")

However, using this code returns the path stripped of slashes:
C:UsersMeDesktopimage.jpg

Could anyone give me a hint how to deal with it?

Posts: 10

Participants: 5

Read full topic


Identifying an Entity (Group) with a Tool (InputPoint or PickHelper)

$
0
0

@medeek wrote:

I am trying to determine the top level group (wall assembly) with my “Add Window” tool as I mouse over it. I know this is probably a very easy piece of code but as I look at the documentation for the InputPoint Class I can’t seem to find the correct method to use to accomplish this. Should I be trying to use the PickHelper Class instead?

Posts: 4

Participants: 3

Read full topic

Arcs and Circles for Preview Tool

$
0
0

@medeek wrote:

I’m quite familiar with the draw method for creating tools with the API. I am wondering though if there is a way to draw preview geometry that is curved: arcs and circles?

On the same note it would useful if I could draw a temporary dimension, I’m sure someone has had a similar requirement to this.

Posts: 1

Participants: 1

Read full topic

IFC relationships has anyone had any joy?

$
0
0

@AndrewRubySketch wrote:

I have created a simple model with walls and windows and assigned them to IfcWall and IfcWindow respectively. The IFC file which I get on Export, doesn’t have any relationship between the IFCWALL and the IFCWINDOW, i.e, the wall should have an association to an opening void and a relationship established that a window fills the void. The things(properties) I wanna see in my IFC file, that are not currently present, are IFCMAPPEDITEM, IFCMAPPEDREPRESENTATION, IFCRELVOIDSELEMENT, IFCRELFILLSELEMENT, IFCWINDOWSTYLE etc.

So, when I view my IFC file in a tree view, there should be a hierarchy where the IfcWall has IfcWindow as a sub-node (like a parent-child relationship).

Also, to make the IFC file shorter, multiple walls should be consistent and be ordered as a group of the same product and the IfcWindowStyle should be associated to windows with common definitions.

I am using the default IFC2X3.xsd as my classification.

Has someone cracked a way to achieve this with Sketchup Export? Thanks.

Posts: 3

Participants: 2

Read full topic

Pushpull to next

$
0
0

@JMZ wrote:

Hello all,

I am wondering if it is possible to Pushpull a face of one component to the next component. For example, if I have a three cubes in a line, is it possible for me to use ruby code to Pushpull the face of one of the cubes to the next cube it would come in contact with? I know SolidWorks has a feature like this that is called “Up to next” but I would like to do something like this in Sketchup using ruby script.

Thank you in advance for any suggestions.

Posts: 3

Participants: 3

Read full topic

How to run a ruby file from a plugin

$
0
0

@JMZ wrote:

Hello,

SketchUp is still pretty new to me so I’m sorry if this question has a very simple answer, but I am wondering if it is possible to call another ruby script from within my plugin and run it. Basically I want to be able to run my plugin which will then run a different ruby code that is saved in a folder inside of the “plugins” folder.

The reason that I’m wondering this is because I have a plugin that creates a webpage that will generate a ruby script that defines instance variables and I want to run this ruby code before running through the rest of the code in the plugin.

Any help on this would be great.

Posts: 2

Participants: 2

Read full topic

Storing empty array in Attribute Dictionaries

$
0
0

@medeek wrote:

So I’m setting my window array initially to an empty array @Windowlist = [] and then storing it as an attribute. When I save the file and then restart SketchUp and re-open the file I notice that the empty array is now “nil” and for some reason I can’t seem to set the variable back to an empty array, very strange behaviour.

Posts: 10

Participants: 4

Read full topic

Sorting arrays

$
0
0

@DanRathbun wrote:

Continuing the discussion from Storing empty array in Attribute Dictionaries:

The Ruby core Array#sort method ? It also takes a block where you can code a custom sorting algorithm.

Yea, that’s a bit vague. What are the keys ? If the numeric values are the hash values, then are the keys going to just be integers? If so, there is no need for a separate hash since you sorted the array and access by integer index is built-in.

Posts: 2

Participants: 2

Read full topic


Will my plugins be compatible with 2018?

$
0
0

@gnebster wrote:

I’ve made plugins that I have been using without problem in SketchUp 2016. I’m thinking about upgrading however am unsure if this will affect my plugins. So I suppose a better question is what has changed as far as the Ruby API goes?

Posts: 3

Participants: 2

Read full topic

Detect Reverse Faces?

$
0
0

@robert.schiriac wrote:

Hello.
Is there a way to detect if the user has clicked Reverse Face?
I have 2 different materials for both front and back for each Face and i need to have the same material on both.
I tried doing that, but on Reverse Face is flipping the material.

front:
58%20AM

front after Reverse Faces:
02%20AM

I didn’t found anything relevant on Ruby API documentation.

Posts: 19

Participants: 9

Read full topic

Offset in sketchup in ruby

$
0
0

@rene.remmelzwaal wrote:

Hi there…
can anyone tell me… how do i offset a face and pushup the border in ruby …?
see example

@num_windows = 4
door_width = 3
door_height = 7
house_height = 9
house_length = (@num_windows + 1) * (door_width + 2) + 2
house_width = 10
roof_height = 2
ents = model.entities

  pl = ents.add_face([0, 0, 0], [0, house_length, 0],
     [house_width, house_length, 0], 
     [house_width, 0, 0], [0, 0, 0])

pl.offset 1
pl.pushpull 1

Posts: 2

Participants: 2

Read full topic

Detecting Presence of Another Group next to a Selected Point(s)

$
0
0

@medeek wrote:

I’m currently working on the auto-corner configuration for the upcoming wall plugin. The idea with this feature is that the plugin or tool will detect the presence of another wall(s) if its start and end corners are placed within a certain distance of these other walls. Once I’ve detected their presence I will drill down into the attribute library of the other wall panel groups, grab their length etc… and also determine the angle between these walls and new wall that I am creating. Based on that information I can then determine if the new wall should have end, outside corners, inside corners, tee corners etc…

Maybe it is just too early in the morning but I’m having troubling trying to come up with a way to efficiently detect another wall. My initial thought is to try and use the bounding box method or something along those lines.

I figured it might not hurt to put this question out there so that I don’t get too far down the wrong path.

Posts: 8

Participants: 4

Read full topic

How to test if a face will be valid

$
0
0

@denis_bolomier wrote:

Hi,
How to test if a face will be valid ?
for exemple:
Sketchup.active_model.entities.add_face([85633.68524760043, -156720.70957342573, 16041.781177255041], [93548.54067123163, -164726.37168133756, 9652.44358096269], [93889.10645925412, -165070.6724738833, 9377.661310890353])

This code will not add face because the triangle is to long. Is it a easyway to test if the triangle will be valid before to create it ?

Best regards

Posts: 20

Participants: 7

Read full topic

Viewing all 3017 articles
Browse latest View live