Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / Xref merge problem + how to stop duplicate xref
  RSS 2.0 ATOM  

Xref merge problem + how to stop duplicate xref
Rate this thread
 
36024
 
Permlink of this thread  
avatar
  • El-d
  • Posted: 27 October 2009 03:39 AM
  • Total Posts: 37
  • Joined: 24 October 2006 04:24 AM

Hi All,
I’ve posted over at CGTalk so you may already have seen this but if not I’m still in need of help :)

I’m midway through hacking together a script(poorly I might add) and have a couple of issues.

The script is designed to scan a series of dummy objects and replace them with xref files.
So far the script works as I would like apart from 2 issues.
When I xref the objects I always end up with an xrefcontroller. If I do it manually, and have merge selected , it doesn’t appear.

xrefs.addNewXRefObject theFile myNewObjs modifiers: #merge manipulators: #merge

I thought this should merge everything as per the buttons but it doesn’t work.
Is there something obvious that I am missing that will just merge the object / no controller?

The second issue ... is now solved .using a unique array.

Thankyou.

El-d



Replies: 0
avatar
  • El-d
  • Posted: 29 October 2009 12:10 AM

Couple of things first.

If you post code always put it in code tags. That prevents the forum from interpreting things in square brackets as tags. e.g. [ i ] (without the spaces) will be interpreted as “begin italics” instead of being actially displayed.
Also, try and keep the code consistently indented (yes, I know the forum screws with it) - makes it much easier to read.

Cheers Steve. I did wonder how to get the code blocks but it seems that if you respond to the post rather than to the thread, you don’t get the options.

for Xobj in XREFNames do
   
(
   i
=i+1
   myNewObjs 
getMAXFileObjectNames xobj
   xrefs
.addNewXRefObject xobj myNewObjs modifiers#merge manipulators: #merge 
   
for obj in shapes where ((subString obj.name 1 OBJNames[i].count) == OBJNames[i]) do
      
(   
      select obj 
      instanceReplace obj myNewObjs
      
print "test"
      
)
   )

You will have to post all the code. There are too many “undefined” variables there - XREFNames, shapes, OBJNames.
Be careful mixing collections as collections and collections as arrays - there’s no guarantee that “for obj in collection...” will be the same sequence as “for i = 1 to collection.count...”.

Rather than fill the entire post with my bad code.
The variables that are absent are:
XREFNames is an array of max files with path.
i.e “C:\temp\test.max” “C:\temp\test01.max”

shapes are just the shapes in the scene(I’m replacing shapes with xref Objects)

OBJNames is the name of the object in the xref file i.e cone01

If I remove the instancereplace, the sequence runs through correctly xrefing the series of files and objects into the scene. In your original example it correctly changes the wire colour of all objects.

I’m guessing that the problem lies within myNewObjs in that it returns the correct name if I print it but if I try to select the object nothing happens. Is it possibly a type issue ie name/string/etc?

Thanks again.
Tim
edit: oh and using 2009.



Replies: 1
/img/forum/dark/default_avatar.png

You’re correct - “comments” don’t have any options to do quotes or code, just type the tags in manually.

this is a quote

and this is code

So, it’s the “instancereplace” which isn’t working and the rest is OK?

Author: Steve_Curley

Replied: 29 October 2009 12:47 AM  
avatar
  • El-d
  • Posted: 29 October 2009 12:53 AM

Correct. I probably should have condensed it all into ‘instancereplace fails’



Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

OBJNames is the name of the object in the xref file i.e cone01

I’m a bit lost there - surely myNewObjs is the list of object names in the xref file?

I think you’re confusing objects and object names - they aren’t interchangable, and your “i” isn’t looping correctly - it will miss some shapes.

Note. I changed some of the variable names to more closely reflect their contents. Always a good idea to use names which give a clue as to what they contain because then you can see if they are of the correct type for the function you’re using. In this case, the instanceReplace requires 2 Nodes, not object Names.

In my test the files contain Box01, Box02, Sphere01, Sphere02.
The scene contained Box01_Shape, Box02_Shape, Box02_Shape01, Sphere01_Shape, Sphere02_Shape, Sphere02_Shape01.

(
xrefFileNames 
#("xref_boxes.max", "xref_spheres.max")
 
for xrefFile in xrefFileNames do
   
(
   xrefObjNames 
getMAXFileObjectNames xrefFile 
   xrefs
.addNewXRefObject xrefFile xrefObjNames modifiers#merge manipulators: #merge  
   
for 1 to xrefObjNames.count do
      
(
      
for obj in shapes where ((subString obj.name 1 xrefObjNames[i].count) == xrefObjNames[i]) do
         
(
--       format "% % %\n" i obj.name xrefObjNames[i]
         instanceReplace obj (getNodeByName xrefObjNames[i])
         )
      )
   )
)

Now, the topic of this thread has something about preventing duplicates - I’ve not addressed that (yet) so you’ll have to explain exactly what you do and don’t want to happen.



Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.

Replies: 0
avatar
  • El-d
  • Posted: 29 October 2009 05:57 AM

With a bit of jiggery pokery I’ve finally got it working :)

The Duplicate part I mentioned was more down to not wanting to import the xref file multiple times which I solved by using a unique array to remove the duplicate items before xref’ing.

The other problem that I mention was in XRef Objects.

If you manually xref an object with merge Transforms then it comes through as XRef Object only
but if you script it, then it always imports an Xref Controller as well.

I thought that the #merge options were supposed to enable the merge checkboxes. Am I misreading this or is it a fault in the script?

Thanks again for all your help, you are a scholar and a gent.



Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

El-d 29 October 2009 12:57 PM

With a bit of jiggery pokery I’ve finally got it working :)

No idea what you jigged (or poked), but hey - if it works… ;)

The Duplicate part I mentioned was more down to not wanting to import the xref file multiple times which I solved by using a unique array to remove the duplicate items before xref’ing.

Ahh. That bit was already working, I think.

The other problem that I mention was in XRef Objects.

If you manually xref an object with merge Transforms then it comes through as XRef Object only
but if you script it, then it always imports an Xref Controller as well.

I thought that the #merge options were supposed to enable the merge checkboxes. Am I misreading this or is it a fault in the script?

Now there you’ve got me. I don’t really use xrefs and I’ve certainly never played with scripting them (before these threads anyway). Might be a case of reading the help - several times while playing with the options - to see what happens. Hopefully it will make sense (eventually).

Thanks again for all your help, you are a scholar and a gent.

You’re welcome. I learn new things about Max every time I answer a question (well almost - the “missing gizmo” one appears like clockwork ;) ) so it’s a 2-way street :)



Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.

Replies: 0