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.lastdidn'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...endwithout success.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement