Load Edge Selection
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/07/2012 at 00:08, xxxxxxxx wrote:
I'm trying to write a script which I can use to load edge selections and then convert to splines on each frame. I'd like the script to remove the spline created on the previous frame before creating the new spline.
I'd also like this to work with deforming objects by running current state to object on the object before creating the spline, however I've left this part out for now as I cannot get the basic function to work yet.
I'm unsure how to load the selection from the edge selection tag. From my research I understand that you shouldn't call GUI stuff from within a threaded context and as I'm using a python tag, I guess this is why I am getting the following error (illegal operation, invalid cross-thread call) when I try and use…
c4d.CallButton(tag,c4d.SELECTIONOBJECT_RESTORE)
The script so far will get the object the tag is attached to, then get the child. If the child is a spline it is removed. Then I iterate through all the tags on the object, if there is an edge selection tag, check the name is 'sketch'. Then I need to load the selection from the tag. Next run edge to spline to create the spline.
I am sure my script is wrong in many ways, but if anyone could help me out with some guidance as to how I might achieve this I'd be very grateful!
Here's the script so far…
import c4d from c4d import utils #Welcome to the world of Python def main() : # get object tag is attached to obj = op.GetObject() # get child object child = obj.GetDown() # If child is spline then remove if child: if child.GetTypeName() == "Spline": child.Remove() #Iterate over all tags on object for tag in obj.GetTags() : if tag.CheckType(c4d.Tedgeselection) : # Determine if tag is edge selection if tag.GetName() == "sketch": # check tag name is sketch source = obj.GetClone() print"select edges here" if c4d.utils.SendModelingCommand(c4d.MCOMMAND_EDGE_TO_SPLINE, [source]) : spline = source.GetDown().GetClone() #Return a clone of the selected splines spline.InsertUnder(obj) return spline
Thanks
Tim -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/07/2012 at 16:01, xxxxxxxx wrote:
After no replies here, I found the solution thanks to Michael Auerswald who is running the fxphd python for C4D course this term. Thanks for your help Michael!
For those interested the code Michael suggested to load the edge selection is as follows
dc = {} dc['id'] = c4d.DescID(c4d.EDGESELECTIONTAG_COMMAND1) edgetag.Message(c4d.MSG_DESCRIPTION_COMMAND, dc) # instead of simulating the button click, we send a message to the tag, which should be thread safe if c4d.utils.SendModelingCommand(c4d.MCOMMAND_EDGE_TO_SPLINE, [obj]) :
Hope that helps someone in the future.
Thanks
Tim -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/07/2012 at 19:28, xxxxxxxx wrote:
Thanks for posting this Tim.
But I'm having trouble getting it to work.import c4d def main() : obj = doc.GetActiveObject() edgetag = obj.GetFirstTag() #First tag is an Edge Selection Tag #This works but might not be thread safe? c4d.CallButton(edgetag,c4d.SELECTIONOBJECT_RESTORE) #Execute the Selection tag to select the stored edges #This does not work: Error: Could not convert 'dict' dc = {} dc['id'] = c4d.DescID(c4d.EDGESELECTIONTAG_COMMAND1) edgetag.Message(c4d.MSG_DESCRIPTION_COMMAND, dc) #instead of simulating the button click, we send a message to the tag, which should be thread safe c4d.EventAdd() if __name__=='__main__': main()
There must be more to it than what you posted?
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/07/2012 at 20:27, xxxxxxxx wrote:
Hi Scott
I only posted the code for executing the command on the edge selection tag, my complete script as it stands is below.
The script sits on a python tag and then looks for an edge selection tag with the name 'sketch', it then runs edge to spline using the selected edges. It also looks for a child of the parent object, checks if it is a spline and then checks the name is parent object name + spline (in other words the name given to the edge to spline - spline). If this is there it is removed. This stops us getting hundreds of splines in the object manager as I only want the spline for the current frame.
The next step is to add currentStateToObject before running the edge to spline, this will allow the script to work with deforming meshes. I haven't got that far yet.
I also think it would be good to loop through the tags and edge to spline any tags which meet the criteria. I think this should be executed as follows
clear any edge selections
iterate through all tags
any edge selection tags called xxxxx
select edges
repeat on all tagsthen run edge to spline
This will create one spline based on all the edge selection tags.
Finally I'd like to add some offset so the spline can be pushed away from the surface slightly using the surface normal plus a multiplier.
So still lots of work to do, but as this is my first real task with python it is slow going but good learning. One step at a time hey!
import c4d LASTFRAME=-1 def findTag(obj, tagtype) : result = [] tags = obj.GetTags() for tag in tags: if tag.CheckType(tagtype) : result.append(tag) return result # returns a list of found tags def main() : global LASTFRAME currentFrame = doc.GetTime().GetFrame(doc.GetFps()) if currentFrame != LASTFRAME: # this is so we don't get an infinite amount of splines, since the tag is evaluated continuously # get object (and object name) tag is attached to obj = op.GetObject() objName = obj.GetName() # get child object child = obj.GetDown() # If child is spline with name from parent then remove if child: if child.GetTypeName() == "Spline": if child.GetName() == str(objName + ".Spline") : child.Remove() edgetag = findTag(obj, c4d.Tedgeselection)[0] if edgetag.GetName() == "sketch": # check tag name is sketch dc = {} dc['id'] = c4d.DescID(c4d.EDGESELECTIONTAG_COMMAND1) edgetag.Message(c4d.MSG_DESCRIPTION_COMMAND, dc) # instead of simulating the button click, we send a messag to the tag, which should be thread safe if c4d.utils.SendModelingCommand(c4d.MCOMMAND_EDGE_TO_SPLINE, [obj]) : spline = obj.GetDown() spline[c4d.SPLINEOBJECT_TYPE] = 1 spline[c4d.SPLINEOBJECT_INTERPOLATION] = 3 # spline.InsertUnder(obj) # Moving spline result from under the original object to the same level as the object c4d.EventAdd() LASTFRAME = currentFrame return True
Cheers
Tim -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/07/2012 at 20:55, xxxxxxxx wrote:
Doh!
The code you posted code only works with R13++.
I get burned on that so many times you'd think I would have learned my lesson by now.Thanks for posting the code.
-ScottA -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/07/2012 at 05:59, xxxxxxxx wrote:
Tim, see if this can be of any help.
It needs a userdata slider on the tag set to "meters" for offsetting
the spline using "normal Move" function.The idea here is only to create the spline if it is not there as
generally one shouldn't generate new objects "on the fly" other
than within a Generator Plugin/Py Generator.
Instead, you set the points of the existing spline from the
virtual generated one.Also, the spline generated is placed -next- to the object instead
of a child. This way one can use deformers as children of the
object and the generated spline will not get deformed twice.In the end thou, it would be recommended to run this in a
Generator Plugin (GetContour() ) for full spline access.Cheers
Lennart# liveSPLINE tcastudios.com©2012 from the idea by T.Clapham import c4d from c4d import utils as u offset = 0.0 def main() : global offset offsetUD = op[c4d.ID_USERDATA,1] # <- UserData in "meters" if offset != offsetUD: offset = offsetUD polyobj = op.GetObject() if not polyobj or not polyobj.CheckType(c4d.Opolygon) : return True tag = polyobj.GetTag(c4d.Tedgeselection) if not tag or tag.GetName() != 'sketch': return True csto_bc = c4d.BaseContainer() csto_objs = u.SendModelingCommand( command = c4d.MCOMMAND_CURRENTSTATETOOBJECT, list = [polyobj], mode = c4d.MODELINGCOMMANDMODE_ALL, bc = csto_bc, doc = doc) bc = c4d.BaseContainer() bc.SetData(c4d.MDATA_NORMALMOVE_VALUE, offset) nmove = u.SendModelingCommand( c4d.ID_MODELING_NORMALMOVE_TOOL, [csto_objs[0]], c4d.MODELINGCOMMANDMODE_ALL, bc) dc = {} dc['id'] = c4d.DescID(c4d.EDGESELECTIONTAG_COMMAND1) tag.Message(c4d.MSG_DESCRIPTION_COMMAND,dc) u.SendModelingCommand(c4d.MCOMMAND_EDGE_TO_SPLINE,[csto_objs[0]]) spline = csto_objs[0].GetDown().GetClone() sname = polyobj.GetName()+'_liveSPLINE' spline.SetName(sname) next = polyobj.GetNext() if next and next.CheckType(c4d.Ospline) and next.GetName() == sname and next.GetPointCount() == spline.GetPointCount() : next.SetAllPoints(spline.GetAllPoints()) next.SetMg(polyobj.GetMg()) next.Message(c4d.MSG_UPDATE) return True else: doc.InsertObject(spline,None,polyobj) return True
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/07/2012 at 16:53, xxxxxxxx wrote:
Hi Lennart
Thanks for taking the time to look and this and offer a solution.
I had a feeling that this should be created as a plugin, is this because using a tag to change the document can cause crashes? I read somewhere that you shouldn't use tags or expressions to do this, I think it was from a comment Bjorn Marl wrote in a thread I saw when researching this.
So basically it is better to create a spline then manipulate the spline using a virtual spline, rather than keep removing and creating a new spline each frame. Makes sense.
I'll look through your code as I'm sure it will be very educational. I managed to hobble mine together through copy and paste of other scripts I found.
Python is definitely something I shall be continuing to learn as I need these type of tools on virtually every project.
Would you mind if I posted your script on my blog (www.helloluxx.com) - it would be free for any one to use and I will credit you and link to tca studios. Of course if you prefer I don't then I'll respect your wishes.
Thanks again - really great of you to help me out.
Cheers
Tim -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/07/2012 at 17:37, xxxxxxxx wrote:
To make a long story short, using expressions to generate objects is generally a big no no.
Simply do not. And by experience, doing a spline web generator trying to use the Py Generator
will end in tears and frustration (hard/impossible to control caches).The -exception- would be to use expressions and the Py Generator as -tools- ,
then bake (PLA and or file series) the result. Then using the result and turn of the "tools".
Still risky..Using Python generating splines, again from my recent experiences, using a Py Generator Plugin
is the only safe and predictable way.As for the code, it is not in any way tested to the extent that I can recommend using it as is, rather
an example for you and your idea. Please only refer to this thread instead as it might lead into more
trouble than joy if people just copy and paste and might be under the impression that it should work fully.I'd be happy thou to try to help you on the steps to a Py Generator Plugin as it was a bit tricky.
You will find traces of the efforts here at PluginCafe'.
i.e here:https://developers.maxon.net/forum/topic/6070/6249_getcontour-refresh-or-uncache-how
Cheers
Lennart -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/07/2012 at 18:07, xxxxxxxx wrote:
Hi Lennart
Thanks for the reply and explanation, seems like it is a rocky road to try and pursue the script as a tag. I will not pass the script on to anyone else, your advice is very valuable as I know you speak from experience.
Thanks for sharing your knowledge (and of course all the great plugins you offer the community). I am taking the python course at fxphd this term, so after 10 weeks I will hopefully be a little more proficient and will no doubt continue to use (and abuse) python for my projects.
I've read through the thread you posted, a lot of it is above my head right now, but I'm sure that won't stop me.
Thanks again.
Tim