[Code] ComponentInstance-add_entities v1.9

[Code] ComponentInstance-add_entities v1.9

Postby TIG » Tue Mar 31, 2009 1:41 pm

This script [ComponentInstance-add_entities.rb] adds an additional method .add_entities to the ComponentInstance class. The given 'entities' (either as a selection or an array) are added to the instance's definition in the same transformation, relationship etc as the originals.
There are two optional arguments - to 'copy' the entities rather than move them and to make the specific instance 'unique' or globally change the definition.
Code: Select all
component_instance(entities,copy,unique)

The two arguments default to 'false' if not given: to set them make them 'true'.
Read the notes at the start of the script. Call it from other scripts. Trying to add an instance into itself or adding an instance's definition recursively could BugSplat - this is trapped by making copies and/or making_unique any instances so added... For Windows users an additional toggleWindows.zip file contains the two files needed in the Plugins folder to give a utility to rollup an open Outliner window during this operation - this will avoid BugSplats [it's based on Jim's code]. If you don't want to install this addition or if you have a Mac then the 'add_entities' method will still work BUT please ensure that the Outliner is not open when using it - it is a known problem in the API itself...
[EDIT: v1.1 new files added 20090401]
[EDIT: v1.2 unneeded file removed, 'defn.delete' now built-in 20090402]
[EDIT: v1.3 unneeded 'require ...' removed 20090408]
[EDIT: v1.4 needed 'group.definition' added direct into file 20090410]
[EDIT: v1.5 'group.definition' empty group error fixed 20090515]
[EDIT: v1.6 definition.behavior(s) fully copied across 20090702]
[EDIT: v1.7 definition attribute dictionaries copied across 20090819]
[EDIT: v1.8 error will attrdicts==nil fixed 20090821]
[EDIT: v1.9 Attribute Dictionaries copied for Instance 20090825]
.
ComponentInstance-add_entities.rb
0
Last edited by TIG on Tue Aug 25, 2009 8:54 am, edited 18 times in total.
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] ComponentInstance-add_entities

Postby thomthom » Tue Mar 31, 2009 1:44 pm

:thumb: :thumb:
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] ComponentInstance-add_entities - v1.1

Postby TIG » Wed Apr 01, 2009 12:32 pm

Version 1.1
It can sometimes BugSplat if the Outliner window is open when it runs...
so it can now be forced to rollup first - using Jim's code ideas - you'll need
'toggleWindows.rb' and 'Win32API.so' - sorry it's for Windows only - Mac users ???
If you are on a PC and don't install toggleWindows.rb/Win32API.so then it'll still work
BUT please close the Outliner to avoid BugSplats !

Version 1.1 20090401
AT-ComponentDefinition-delete.rb version used.
Recursive version now keeps layer/material.
Possible Outliner window rollup added.


You should download the following files:
ComponentInstance-add_entities.rb
AT-ComponentDefinition-delete.rb [ viewtopic.php?p=145255#p145255 ]
for PC users the zip file contains 'toggleWindows.rb' and 'Win32API.so'...

They are added to the first page in this thread...[ viewtopic.php?p=145009#p145009 ]
0
Last edited by TIG on Wed Apr 01, 2009 1:36 pm, edited 1 time in total.
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] ComponentInstance-add_entities

Postby thomthom » Wed Apr 01, 2009 12:50 pm

Is there a way to know if the Outliner is open? If so, can't you use Sketchup.send_action 21513 to toggle the Outliner off and have it work on both platform?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] ComponentInstance-add_entities

Postby TIG » Wed Apr 01, 2009 1:02 pm

thomthom wrote:Is there a way to know if the Outliner is open? If so, can't you use Sketchup.send_action 21513 to toggle the Outliner off and have it work on both platform?

It would be good if it were cross-platform BUT the "send_action 'number'" only works on a PC...
If someone has a Mac fix please let me know...
The toggleWindows script lets you 'rollup' any open window by name on a PC...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [code] ComponentInstance-add_entities - v1.2

Postby TIG » Thu Apr 02, 2009 10:10 am

Version 1.2 is here [ viewtopic.php?p=145009#p145009 ]
It now has the 'definition.delete' code built-in as that is now greatly simplified thanks to AlexM's insights...
I'm awaiting Scott's feedback on cross-platform Sketchup.send_action(21513) etc - I don't think they are Mac friendly... However if they are we can make the v1.1 Outliner crash work-around for PC and Mac...

.
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [code] ComponentInstance-add_entities

Postby thomthom » Thu Apr 02, 2009 10:26 am

Does Mac also have the issue with the open Outliner? It's not specific to the way Windows redraws stuff?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] ComponentInstance-add_entities

Postby TIG » Thu Apr 02, 2009 10:31 am

thomthom wrote:Does Mac also have the issue with the open Outliner? It's not specific to the way Windows redraws stuff?

Don't know - are there any Mac users out there getting BugSplats with the Outliner being open during script runs that affect groups/instances ???
Any Mac users doing 'send_action' - please try to open/close the Outliner and try Sketchup.send_action(21513) etc and report back...
It would be good to have extended common 'send_actions' for both PC and Mac - I know that some 'numerical' ones don't work on Mac...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [code] ComponentInstance-add_entities

Postby thomthom » Thu Apr 02, 2009 10:43 am

I have an old Mac Mini at home I can test the send_actions on.
Not sure if it's reliable to test the Outliner issue due to it's age and lack of power...
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] ComponentInstance-add_entities

Postby TIG » Thu Apr 02, 2009 10:49 am

thomthom wrote:I have an old Mac Mini at home I can test the send_actions on.
Not sure if it's reliable to test the Outliner issue due to it's age and lack of power...

Thanks - Scott's taking his time coming back... I suspect it's not going to be straight forward...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [code] ComponentInstance-add_entities

Postby Matt666 » Thu Apr 02, 2009 11:22 am

I reported this Mac bug here... I hope outliner test will be positive...
0
Frenglish at its best !
My scripts

Matt666 
 

Re: [code] ComponentInstance-add_entities - v1.3

Postby TIG » Wed Apr 08, 2009 9:52 am

v1.3 is here viewtopic.php?p=145009#p145009
IT has an unneeded initial 'require ...' removed: otherwise it's unchanged...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [code] ComponentInstance-add_entities

Postby Matt666 » Fri Apr 10, 2009 9:15 am

Hi TIG.
I start to play with your cool function!
Just one bug for the moment, line 139. group.definition, and no definition function for groups.
I think you didn't copy the function in the script... ;)
Code: Select all
class Sketchup::Group
   def definition
      return self.entities[0].parent
   end
end   
0
Frenglish at its best !
My scripts

Matt666 
 

Re: [code] ComponentInstance-add_entities

Postby TIG » Fri Apr 10, 2009 12:48 pm

Matt = thanks for pointing this out - I had 'group.definition' load from a separate ruby - that I hadn't posted...
I've now added it to this file for the avoidance of doubt...

v1.4 now here: viewtopic.php?p=145009#p145009

Being able to get a group's definition is very useful in many other cases...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [code] ComponentInstance-add_entities

Postby HPW » Mon May 11, 2009 10:09 am

So now we have this great addition to the toolset, what is the best way of delivery?
The file gets copied into the Plugins-Directory.

What should our own installer should do?
Check the existence of the file and install it if not present?
Check date and install it if a newer version is available?

Can the ruby-code check if the method is installed?
If not use a copy installed in the own subfolder?
0

HPW 
 

Re: [code] ComponentInstance-add_entities

Postby TIG » Mon May 11, 2009 10:24 am

The file gets copied into the Plugins-Directory.
Your own installer should check the existence of the file and install it if not present, BUT also check any existing file's modification-date and install if you have a newer version.

Yes to all, this is the best way for all plugins...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [code] ComponentInstance-add_entities

Postby AlexMozg » Thu May 14, 2009 10:28 pm

Method 'group.definition'....
More correct would be the code:
Code: Select all
class Sketchup::Group
   def definition
      self.entities.parent
   end
end

Because, when group is empty
there is an error at the use of code: self.entities[0].parent
The group may be empty soon after its inception.
For example:
Code: Select all
group = Sketchup.active_model.active_entities.add_group
definition = group.definition

Request to replace a code on more correct, because I use this method in the developments.
:!:
0

AlexMozg 
PluginStore Author
PluginStore Author
 

Re: [code] ComponentInstance-add_entities - UPDATE

Postby TIG » Fri May 15, 2009 10:53 pm

Following AlexM's point I have adjusted to code to avoid empty group errors...
v1.5 is now here... viewtopic.php?p=145009#p145009
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [code] ComponentInstance-add_entities UPDATE

Postby TIG » Thu Jul 02, 2009 5:23 pm

An oversight has been corrected...

    v1.6 all definition.behavior(s) now fully copied across. 20090702
download it from... viewtopic.php?p=145009#p145009
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [code] ComponentInstance-add_entities

Postby HPW » Thu Aug 06, 2009 7:31 am

I run into a problem when I use add_entities from a startup-ruby.
The code line:

Code: Select all
@kombi_group_sel_def.instances[0].add_entities(@kombi_group_list)


throws an error : undefined method `parent' for nil:NilClass

My ruby (zAutostart.rb) loads after the ComponentInstance-add_entities.rb

When I disable the call in my ruby and start the command from the console it runs without problems.
0

HPW 
 

Re: [code] ComponentInstance-add_entities

Postby thomthom » Thu Aug 06, 2009 7:50 am

Are you sure you have an instance of that definition in your model?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] ComponentInstance-add_entities

Postby HPW » Thu Aug 06, 2009 7:54 am

thomthom wrote:Are you sure you have an instance of that definition in your model?


Yes, because when I outcomment my call and type it in the console after start-complete it works.

Therefor I build just a workaround:

Code: Select all
 wsh = WIN32OLE.new('Wscript.Shell')
 if wsh.AppActivate(skpbasename+".skp - SketchUp")
  sleep(1)
  wsh.SendKeys('{F2}')
  sleep(1)
  wsh.SendKeys('convert_acad_import{ENTER}')
 end


Seems that ruby's on startup have problems to use other stuff from other startup-rubys.
0

HPW 
 

Re: [code] ComponentInstance-add_entities

Postby thomthom » Thu Aug 06, 2009 8:23 am

HPW wrote:Seems that ruby's on startup have problems to use other stuff from other startup-rubys.

Hm.. maybe you're calling a ruby that isn't loaded. Have you added an require statement for all the rubys you depend on?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] ComponentInstance-add_entities

Postby HPW » Thu Aug 06, 2009 8:26 am

Cannot be true, because the error come from inside the add_entities-code.
Otherwise the error would tell about unknown method.
0

HPW 
 

Re: [code] ComponentInstance-add_entities

Postby thomthom » Thu Aug 06, 2009 8:32 am

Maybe things aren't ready immediately when SU loads the plugins...
Have you tried using a timer to delay the execution of your script instead of having to send keystrokes`?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] ComponentInstance-add_entities

Postby TIG » Thu Aug 06, 2009 9:08 am

require 'toggleWindows.rb' ?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [code] ComponentInstance-add_entities

Postby HPW » Thu Aug 06, 2009 9:29 am

thomthom wrote:Maybe things aren't ready immediately when SU loads the plugins...
Have you tried using a timer to delay the execution of your script instead of having to send keystrokes`?


I tried a 'sleep' with some diferent values without any success.

TIG wrote:require 'toggleWindows.rb' ?


I had it yet for closing the outliner.
With my workaround it is working fine now.
(Automated DWG-Creation and SKP-Conversion(Acad-Blocks to SU-DC with non-editable prop) in a Batch process.)
0

HPW 
 

Re: [code] ComponentInstance-add_entities

Postby thomthom » Thu Aug 06, 2009 9:36 am

HPW wrote:I tried a 'sleep' with some diferent values without any success.

sleep prevents everything else to process. If you use a timer you allow the rest to continue processing.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] ComponentInstance-add_entities

Postby TIG » Wed Aug 19, 2009 8:18 pm

v1.7 is now available - now any Attribute Dictionaries the Definition might have are kept when the Definition is reworked with the new entities...

viewtopic.php?p=145009#p145009

.
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [code] ComponentInstance-add_entities

Postby HPW » Fri Aug 21, 2009 7:37 am

Using 1.7 instead of 1.6 gives me this error:
convert_acad_import
Error: #<NoMethodError: C:/Programme/Google/Google SketchUp 7/Plugins/ComponentInstance-add_entities17.rb:188:in `add_entities': undefined method `each' for nil:NilClass>
C:/Programme/Google/Google SketchUp 7/Plugins/ComponentInstance-add_entities17.rb:188
0

HPW 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 

Next


 

Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 7 guests

Visit our sponsors: