Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography



Maxunderground news unavailable

 
First page  Go to the previous page   [01]  [02]  Go to the next page  Last page
 
Object not aligning to pivot (maxscript)
show user profile  jpedleham
Im trying to place a star at the pivot point of lots of objects but no matter what i try they end up at 0,0,0. If i set it to place them at the center that works fine but .pos seems to place them at 0,0,0 regardless. It worked once. for no apparent reason with no changes. But not it refuses to work. Any ideas?


sceneobjects = for o in objects collect o


for obj in 1 to sceneobjects.count do
(
dummyObj = star()
dummyObj.pos = sceneobjects[obj].pos-- move dummy to insertion point
dummyObj.parent = sceneobjects[obj] --parent dummy to block
dummyObj.name = "D_" + sceneobjects[obj].name --rename dummy

)

read 265 times
1/17/2017 5:18:30 PM (last edit: 1/17/2017 5:18:30 PM)
show user profile  ScotlandDave
I regularly jump between C++/C#/Python and occasionally maxscript so forget syntax but try just:

obj.pos

Instead of:

sceneobjects[obj].pos



Website | Blog | Contact | Vimeo

read 257 times
1/17/2017 5:37:45 PM (last edit: 1/17/2017 5:37:45 PM)
show user profile  HANZZ
Pics of the scene?...
Depending on what you're trying to actually do, and how you're doing it, and how many objects you're talking about, you could make a duplicate scene, attach all the objects into one, then go to the pivot tab and center the pivot to the mass object's center. Get that coord, go back to your previous scene and go from there. Unless you're trying to animate some object moving to the object/s center, then my approach works for you.

 photo MorgothArisenSig_zpsup4yjp7o.jpg

read 249 times
1/17/2017 6:10:06 PM (last edit: 1/17/2017 6:10:06 PM)
show user profile  jpedleham
Basically its a linked DWG cad plan that will change alot over the coming months and i want to put a process in place whereby i can assign models to the cad blocks and then when the layout changes i can just reload the link and the models move with the cad blocks.

Im trying to add a shape or helper to each block because currently i cant do import>replace on the cad plan as its linked and it doesnt allow it.

What i want to do is link my cad plan, assign a helper or shape that is parented to the block and then run my replacer to replace the 'dummy' object with the actual model that the cad block corresponds to. Theres about 2000 blocks in the scene.

Ive just realised i also need instancing on the dummy objects if the object its parented to is an instance. this might be alot more complicated than i first thought.
read 245 times
1/17/2017 8:23:35 PM (last edit: 1/17/2017 8:23:35 PM)
show user profile  Garp
This works for me:
for obj in objects as array do star pos:obj.pos name:("D_" + obj.name) parent:obj





read 229 times
1/19/2017 6:01:30 AM (last edit: 1/19/2017 6:01:30 AM)
show user profile  jpedleham
Thanks Garp.
I got it working in the end by using .transform instead of .pos but your code is much cleaner so ill use that
read 223 times
1/19/2017 9:35:29 AM (last edit: 1/19/2017 9:35:29 AM)
show user profile  Garp
Apology, jpedleham. I just reread your second post, this time all the way to the end. I missed the bit about the instances.
I suspect this is going to require a bit of hacking. Give me a moment...




read 212 times
1/19/2017 6:10:02 PM (last edit: 1/19/2017 6:10:02 PM)
show user profile  Garp
Got it :) And it did take a couple of simple hacks involving the instance manager.

First, there is no is_instace() method in maxscript. Fortunately, InstanceMgr.canMakeObjectsUnique() does just the same.

Second, InstanceMgr.getInstances() gives an array reference of all the instances of its argument. As the code iterates through the objects in the scene, the trick I used to not collect the same array ref of instances for how many instances there are in the set is to collect it only when the current object appears in the first position in its own set of instances. Hope it makes sense.

The script does two passes.
In the first one, it tests the current object and either collects the instances or parents a star (if it's not an instance).
In the second, for each set of instances it parents an instance of the same star (unique to this set) to each instance.



read 207 times
1/19/2017 7:14:31 PM (last edit: 1/20/2017 2:10:40 AM)
show user profile  jpedleham
Youre a genius Garp!
Thanks for your help it works brilliantly!
read 171 times
1/23/2017 10:55:47 AM (last edit: 1/23/2017 10:55:47 AM)
show user profile  jpedleham
Im trying to fiddle with your code a little to fit some more manual steps in but it throws an error whenever i try and do my thing.

Instead of adding D_ to the beginning, id like to name the stars the same as their parent blocks minus the first 6 characters. Eg the parent is called Block:A12-3456 and the star is called A12-3456.

I tried using trimleft but it throws an error but it could be down to me not using it in the correct place.
read 162 times
1/23/2017 3:33:00 PM (last edit: 1/23/2017 3:33:00 PM)
show user profile  jpedleham
Im also having a problem which could be entirely autodesks problem but the same thing is happening where by my stars all end up at 0,0,0 on a new scene with a freshly linked file and a straight copy from your code.
read 159 times
1/23/2017 3:45:20 PM (last edit: 1/23/2017 3:45:20 PM)
show user profile  Garp
Use substring() instead of trimleft() which is a character parsing method.
s1 = "Block:A12-3456"
s2 = substring s1 7 -1
-> "A12-3456"


No idea about the zeroing out of the positions. Works fine on my end.
Try to add some output in the code to see what positions mxs is reading from your file.




read 154 times
1/23/2017 8:15:42 PM (last edit: 1/23/2017 8:15:42 PM)
show user profile  jpedleham
Its very strange. It was working fine on my end too and then all of a sudden it stopped working one time and then it wont go back. Ill add some output and see what i can get out of it.

Thanks
read 143 times
1/24/2017 9:26:22 AM (last edit: 1/24/2017 9:26:22 AM)
show user profile  jpedleham
(
local all_insts = #()

for obj in objects as array do
if InstanceMgr.canMakeObjectsUnique obj then (
InstanceMgr.getInstances obj &loc_insts
if loc_insts[1] == obj do
append all_insts loc_insts
) else
s1 = obj.name
s2 = substring s1 7 -1
star pos:obj.pos name:s2 parent:obj
print obj.pos


for loc_insts in all_insts do (
local s = star()
for inst in loc_insts do
s3 = inst.name
s4 = substring s3 7 -1
instance s pos:inst.pos name:s4 parent:inst
print inst.pos
delete s
)
)


So this is what i have and whilst i can read and understandwhats going on in maxscript im not fluent enough to write it without problems yet. For example i get a 'no substring function for undefined' error. When i remove that i then get a 'no pos function for undefined' too. Perhaps im referencing something incorrectly?


read 142 times
1/24/2017 9:35:47 AM (last edit: 1/24/2017 9:36:21 AM)
show user profile  ScotlandDave
Could be a grouping issue with objects in the scene, maxscript can be skittish with objects that are in closed groups..



Website | Blog | Contact | Vimeo

read 139 times
1/24/2017 10:29:49 AM (last edit: 1/24/2017 10:29:49 AM)
 
First page  Go to the previous page   [01]  [02]  Go to the next page  Last page
 
#Maxforums IRC
Open chat window


Support Maxforums.org