Model.import() always true?
-
Hi,
I'm trying to import collada files via the API. After importing, I want to apply some transformations to those files.
According to the API, the Model.import method returnstrue
/false
, but not the imported object.First Question: Is there a direct way to get the imported component instance? My current workaround is to get the last element of Model.entities:
imported=@model.entities[@model.entities.length-1]
(@model.entities.last
didn't work for me)
This workaround makes only sense if the last element is actually the imported component instance and if the import was successful.The second problem is: When I import a corrupted collada file, the import should fail and return
false
, but for me it returnstrue
. Is this a bug in the API, or does it depend how the import fails? -
@aerilius said:
First Question:
cache = model.entities.to_a model.import( ... ) imported_instance = ( model.entities.to_a - cache ).first
-
Or...
Do the import, then immediately
defn=model.definitions.to_a[-1] instance=defn.instances[0]
then useinstance.transform!(tr)
where 'tr' is the required transformation.
Or it's it's easier for you to make a new transformation from scratch use
instance.erase!
followed by
instance=model.active_entities.add_instance(defn, tr)
where 'tr' is the required transformation... -
Thanks!
-
@aerilius said:
The second problem is: When I import a corrupted collada file, the import should fail and return
false
, but for me it returnstrue
. Is this a bug in the API, or does it depend how the import fails?Do you have "Validate Collada File" checked in the Import Options dialog ??
When the import "fails" does Sketchup raise any Ruby exception that can be trapped with a begin .. rescue .. end block?
-
For yery corrupted collada files, there appears just a messagebox "import failed [OK]". The ruby console does not display any exception but just
true``
.For some collada files, SketchUp says there is a chance that the import could fail and asks if I want to continue [yes]/[no].
If I click yes, it succeeds to import it anyways, if I click no, the same messagebox appears "import failed [Ok]. In all cases, the console saystrue
. I tried it withbegin
...rescue
...end
without success.
Advertisement