  | | | checking that an object exists | checking that an object exists 2005-04-07 - By Jason Brynford-Jones
Back And here is a link to more http://www.xsibase.com/forum/index.php?board=14;action=display;threadid= 17688 -- --Original Message-- -- From: owner-xsi@(protected) [mailto:owner-xsi@(protected)] On Behalf Of Bradley R. Gabe Sent: Thursday, April 07, 2005 3:14 PM To: XSI@(protected) Subject: Re: checking that an object exists You can always try to populate an XSI collection using the items property set to a string. If the objects don't exist in the scene, the collection count will remain 0. Otherwise, it will fill up with the items that match the string input. This is very fast and never raises errors:
// Create an empty XSI collection var findColl = new ActiveXObject('XSI.Collection');
// Find the object from the name findColl.Items = 'objectName';
// Test the collection count if(findColl.count>0){ var obj = findColl(0); LogMessage(obj); } // -- ---- ---- ---- ---- ---- ---- ---- ------
NOTE: This is the same way the Selection object gets populated when you type a string in the text selection box, so you can always test your strings before you put them into your code. Also, wildcard selections will work with this method, so you could use it to quickly grab all the nodes in a specific model space:
// Create an empty XSI collection var modelColl = new ActiveXObject('XSI.Collection');
// Get the name of the current selected model var modelName = selection(0).name;
// Get all the nodes in the model space modelColl.Items = modelName + '.*'; // -- ---- ---- ---- ---- ---- ---- ---- ------
You can also use this technique to fill a collection with multiple parameters or properties. I like to use an Array because it reads clearly, requires less string concatenation, and is easy to add or remove items from:
// Create an empty XSI collection var visColl = new ActiveXObject('XSI.Collection');
// Get the visibility parameters of the currently selected obj var obj = selection(0);
visColl.Items = [ obj + '.visibility.viewvis', obj + '.visibility.rendvis', obj + '.visibility.selectability' ];
// Get pointers to the visibility params var viewvis = visColl(0); var rendvis = visColl(1); var selectability = visColl(2); // -- ---- ---- ---- ---- ---- ---- ---- ------
If you're interested in more techniques for getting object pointers and speed comparisons, check out this link: http://www.cg-soup.com/archives/2005/02/loopin_lizards.html
-Brad CG Soup
Hi,
I got an interesting question from someone, that I wanted to check out with you all.
Given an object's full name, he wants to check if it exists.
So there are two ways to do it.
Via command: GetValue()
Via object model: Dictionary.GetObject()
now here's the question:
Both of these solutions throw an exception if the given object does not exist. While you can catch the exception, I'd think this is a poor way to go about solving the problem. Exceptions should not be used for flow control. They're inherently slow (or so I've been taught time and time again). Is there a better fast way to check if an object exists from its full name that doesn't involve depending on exceptions? I can come up with some ways of doing it that will be inherently slow... but none that are fast.
-brad --- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas -microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=ProgId content=Word.Document> <meta name=Generator content="Microsoft Word 10"> <meta name=Originator content="Microsoft Word 10"> <link rel=File-List href="cid:filelist.xml@(protected)"> <!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:DoNotRelyOnCSS/> </o:OfficeDocumentSettings> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:SpellingState>Clean</w:SpellingState> <w:GrammarState>Clean</w:GrammarState> <w:DocumentKind>DocumentEmail</w:DocumentKind> <w:EnvelopeVis/> <w:Compatibility> <w:UseFELayout/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--> <style> <!-- /* Font Definitions */ @(protected) {font-family:Courier; panose-1 (See http://ose-1.ora-code.com):2 7 4 9 2 2 5 2 4 4; mso-font-charset:0; mso-generic-font-family:modern; mso-font-format:other; mso-font-pitch:fixed; mso-font-signature:3 0 0 0 1 0;} @(protected) {font-family:"MS Mincho"; panose-1 (See http://ose-1.ora-code.com):2 2 6 9 4 2 5 8 3 4; mso-font-alt:"\FF2D\FF33 \660E\671D"; mso-font-charset:128; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @(protected) {font-family:Tahoma; panose-1 (See http://ose-1.ora-code.com):2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:1627421319 -2147483648 8 0 66047 0;} @(protected) {font-family:"\@(protected) Mincho"; panose-1 (See http://ose-1.ora-code.com):2 2 6 9 4 2 5 8 3 4; mso-font-charset:128; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"MS Mincho";} a:link, span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:blue; text-decoration:underline; text-underline:single;} span.EmailStyle17 {mso-style-type:personal-reply; mso-style-noshow:yes; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; font-family:Arial; mso-ascii-font-family:Arial; mso-hansi-font-family:Arial; mso-bidi-font-family:Arial; color:navy;} @(protected) Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]--> </head>
<body lang=EN-US link=blue vlink=blue style='tab-interval:.5in'>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size: 10.0pt;font-family:Arial;color:navy'>And here is a link to more<o:p></o:p>< /span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size: 10.0pt;font-family:Arial;color:navy'><a href="http://www.xsibase.com/forum/index.php?board=14;action=display;threadid =17688">http://www.xsibase.com/forum/index.php?board=14;action=display;threadid =17688</a><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>-- --Original Message-- --<br> <b><span style='font-weight:bold'>From:</span></b> owner-xsi@(protected) [mailto:owner-xsi@(protected)] <b><span style='font-weight:bold'>On Behalf Of </span></b>Bradley R. Gabe<br> <b><span style='font-weight:bold'>Sent:</span></b> Thursday, April 07, 2005 3:14 PM<br> <b><span style='font-weight:bold'>To:</span></b> XSI@(protected)<br> <b><span style='font-weight:bold'>Subject:</span></b> Re: checking that an object exists</span></font></p>
<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman" ><span style='font-size:12.0pt'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman" ><span style='font-size:12.0pt'>You can always try to populate an XSI collection using the items property set to a string. If the objects don't exist in the scene, the collection count will remain 0. Otherwise, it will fill up with the items that match the string input. This is very fast and never raises errors:<br> <br> </span></font><font color=green face="Courier New"><span style='font-family: "Courier New";color:green'>// Create an empty XSI collection<br> </span></font><font face="Courier New"><span style='font-family:"Courier New"' >var findColl = new ActiveXObject('XSI.Collection');<br> <br> <font color=green><span style='color:green'>// Find the object from the name<br> </span></font>findColl.Items = 'objectName';<br> <br> <font color=green><span style='color:green'>// Test the collection count<br> </span></font>if(findColl.count>0){<br> var obj = findColl(0);<br> LogMessage(obj);<br> }<br> <font color=green><span style='color:green'>// -- ---- ---- ---- ---- ---- ---- ---- ------<br> <br> </span></font></span></font>NOTE: This is the same way the Selection object gets populated when you type a string in the text selection box, so you can always test your strings before you put them into your code. Also, wildcard selections will work with this method, so you could use it to quickly grab all the nodes in a specific model space:<br> <br> <font color=green face="Courier New"><span style='font-family:"Courier New"; color:green'>// Create an empty XSI collection<br> </span></font><font face="Courier New"><span style='font-family:"Courier New"' >var modelColl = new ActiveXObject('XSI.Collection');<br> <br> <font color=green><span style='color:green'>// Get the name of the current selected model<br> </span></font>var modelName = selection(0).name;<br> <br> <font color=green><span style='color:green'>// Get all the nodes in the model space<br> </span></font>modelColl.Items = modelName + '.*';<br> <font color=green><span style='color:green'>// -- ---- ---- ---- ---- ---- ---- ---- ------<br> <br> </span></font></span></font>You can also use this technique to fill a collection with multiple parameters or properties. I like to use an Array because it reads clearly, requires less string concatenation, and is easy to add or remove items from:<br> <br> <font color=green face="Courier New"><span style='font-family:"Courier New"; color:green'>// Create an empty XSI collection<br> </span></font><font face="Courier New"><span style='font-family:"Courier New"' >var visColl = new ActiveXObject('XSI.Collection');<br> <br> <font color=green><span style='color:green'>// Get the visibility parameters of the currently selected obj<br> </span></font>var obj = selection(0);<br> <br> </span></font><font face=Courier><span style='font-family:Courier'>visColl.Items = [<br> obj + '.visibility.viewvis',<br> obj + '.visibility.rendvis',<br> obj + '.visibility.selectability'<br> ];<br> <br> </span></font><font color=green face="Courier New"><span style='font-family: "Courier New";color:green'>// Get pointers to the visibility params<br> </span></font><font face="Courier New"><span style='font-family:"Courier New"' >var viewvis = visColl(0);<br> var rendvis = visColl(1);<br> var selectability = visColl(2);<br> <font color=green><span style='color:green'>// -- ---- ---- ---- ---- ---- ---- ---- ------<br> <br> </span></font></span></font>If you're interested in more techniques for getting object pointers and speed comparisons, check out this link:<br> <a href="http://www.cg-soup.com/archives/2005/02/loopin_lizards.html" eudora=autourl>http://www.cg-soup.com/archives/2005/02/loopin_lizards.html<br> <br> <br> </a>-Brad<br> CG Soup<br> <br style='mso-special-character:line-break'> <![if !supportLineBreakNewLine]><br style='mso-special-character:line-break'> <![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman" ><span style='font-size:12.0pt'>Hi,<br> <br> I got an interesting question from someone, that I wanted to check out with you all.<br> <br> Given an object's full name, he wants to check if it exists.<br> <br> So there are two ways to do it.<br> <br> Via command: GetValue()<br> <br> Via object model: Dictionary.GetObject()<br> <br> now here's the question:<br> <br> Both of these solutions throw an exception if the given object does not exist. While you can catch the exception, I'd think this is a poor way to go about solving the problem. Exceptions should not be used for flow control. They're inherently slow (or so I've been taught time and time again). Is there a better fast way to check if an object exists from its full name that doesn't involve depending on exceptions? I can come up with some ways of doing it that will be inherently slow... but none that are fast.<br> <br> -brad<br> ---<br> Unsubscribe? Mail Majordomo@(protected) with the following text in body:<br> unsubscribe xsi<o:p></o:p></span></font></p>
</div>
</body>
</html>
|
|
|