Components involuntarily becoming unique upon importation
-
Hi,
A lot of my component instances, rename themselves, ultimately creating new component definitions, increasing file size & leaving me unable update all instances at once by editing one instance.
For example, I have components saved in the component library, with a component definition name of my choice e.g "spectacles" which I have imported into my model:
https://dl.dropbox.com/u/72912548/posts/spectacles.JPG
Then when I import this file again, the component definition changes(#1,#2 etc gets added):
https://dl.dropbox.com/u/72912548/posts/spectacles%233.JPG
Does anyone have a solution? or any way round this problem which would allow me to rename all instances as one definition quickly? I am starting to learn ruby code to try & solve the issue & have the following code(thanks to TIG and Abdullah) to locate all families of a particular component, which can then be then be replaced with a desired definition:
n="match";m=Sketchup.active_model;s=m.selection;s.clear;m.definitions.each{|d|s.add d.instances if d.name=~/#{n}/}
but it is still a slow process & i am wasting valuable time doing so, so any help would be greatly appreciated
Thanks
-
When you 'Import' a SKP file again into a model that already contains it [or drag/drop it into your model which is the equivalent to 'Import'] then Sketchup assumes that you want another version and appends the #N to the name, making another 'definition'.
BUT why do that ?
After you 'Import' it once the Component is added into your Model tab of the Components Browser - i.e. it has been added to themodel.definitions
...
So when you next want to use that Component you can simply click its icon in the tab of the Browser and reuse it. There is no need to re-import it at all...If you have an external component SKP that you have edited and want the equivalent version previously inserted in the current model to be similarly updated... then you use the context-menu 'Reload' whilst having an instance of it selected in the model OR over its icon in the Model tab of the Component Browser...
If you are trying to do something 'in code'... then you can set up a test to see if it exists first and if not then you load it...
defn=model.definitions.load('fullpathtoskpname.skp') unless defn=model.definitions['skpname']
This sets 'defn' as a reference to the definition named 'skpname', first loading it from its external SKP file only IF it doesn't exist already in the model's definitions...To place a definition in code you would then use
model.active_entities.add_instance(defn, tr)
where 'tr' is a transformation you need to make, specifying the new instance's location/rotation/scaling etc... -
Hi TIG, sorry I should have been more clear. I always import components, from my component library, in the component browser. I save them here, too.
To explore the issue further, I tried importing a component(definition name:spectacles), to a file which already had this definition nested within a component(definition name:spectacles display). It was appended to spectacles#1.
To remedy this, I tried repeating the process, but reloaded the spectacles nested within the spectacles display (via right clicking them in the outliner), to ensure they were exactly the same component. They appended again .
As a last attempt, I repeating this process, but saved the spectacles display component, after reloading the nested spectacles, in order to prompt SU to update, before I imported the spectacles, which this time were not appended .
So I guess it's about being diligent & making sure SU is updated, unless there's anything i'm missing???
Secondly, I'm new to coding, would you put:
model.definitions.load('fullpathtoskpname.skp')
in place of "defn" in your second snippet?
Cheers
-
If you are talking code I have no idea, but if you are simply having problems placing components manually then it is to do with "Import".
If you place a component from the component browser it will be spectacles.
If you "import it" it will be spectacles#1. -
Please stop reimporting your components into the same model from your 'libraries'... UNLESS you really do want duplicated 'incrementing' names !
Once they have been loaded into the model the first time, then please use the components shown in the model-tab of the component-broswer, to place additional instances of that same component... they will then use the same name...
When you import a new component and there's already a component definition using the same name then quite sensibly SketchUp assumes you want it as a 'duplicate' [xx, xx#1, xx#2 etc], BUT when you reuse [from the model-tab] a previously loaded component to place another instance into the model, then you won't get incremented naming - simply because all of them will be instances of that original single component...
Are you sure you really understand the process that you are meant to follow when doing this ?
-
In case TIG hasn't made it clear enough, if you don't want unique components, drag in additional instances from the In Model component library not the location you have been dragging them in from.
-
yes I understand that using the in model-tab of the component-browser, will place additional instances, however the component I want, is nested within another component, in the currently open file. Therefore it does not appear in the model-tab of the component browser, so i cant get at it. So what should i do?
As you said importing from the file menu doesn't solve the problem, so I thought making a component library, within the component browser to import from might solve the problem as shown in this youtube video(not mine):
cheers
-
There is an option to 'Expand' the component-definitions that are listed in the component-browser's model-tab which then includes the nested ones [it's the second item from the bottom in the fly-out menu, activated from the arrow icon on the right-side when in the model-tab]...
This will then give you access to those components that are not placed directly into the model but are actually nested inside other components that you have imported... all without recourse to re-importing them afresh... -
Cheers TIG, can't believe i missed that, all this time. That little bit of info is worth its weight in gold, should save lots of time now.
Thanks for the codes too, they should provide some good avenues for me to explore ruby coding.
Advertisement