@seven6ty (seven6ty) posted a new topic, subject "snapping CV points of one obj to another?". It read:

   Hi.
    
    I'm writing a script that will basically, take two CV control curves that are the same shape, only in different spots, and snap the curves of the first to the second.
    
    The main problem I'm having right now is finding out how to query how many CV's make up each object. Anyone know how to go about doing this??? Any leads on useful commands or such would be much appreciated, thanks!

To which @Jhavna (Jhavna) replied

    Well, I was going to suggest the rebuildCurve command with the -spans query option.  
    But I tried it and I get this error:
    
    > rebuildCurve -q -s curve1;  
    >  // Error: No object was specified to query //
    
    I was hoping that it would return the number of spans of the curve (curve1). :shrug:
    
    Anyone have any idea why I get that error? The manual says that the spans flag can be queried…

After which, @ajk48n (ajk48n) added

    I believe you can't actually query for the number of CV's, since it's a combination of the curve spans and degree.
    
    Here is a somewhat limited script. It only works if the curve is open, and I wasn't quite sure how you go about finding the number of CV's, but adding the spans and degree count together worked. At least for open curves anyway.  
    You also have to query the “shape” node of the curve. This script will add the shape node onto the end of whatever is selected. It will work if your curve is named something without a number at the end. I didn't add support for having a number at the end, since Maya puts the “shape” after the word, but before the number.
    
    {  
    $curveName = `ls -sl`;  
    string $curveShapeName = ($curveName[0] + “Shape”);  
    if (`getAttr $curveShapeName.form` == 0) //open Curve  
    {  
    [indent] $curveDeg = `getAttr ($curveShapeName + ".degree")`;  
    [/indent][indent] $curveShape = `getAttr ($curveShapeName + ".spans")`;  
    [/indent][indent]$curveCV = $curveDeg + $curveShape;  
    [/indent][indent] print ("  
    CV count: " + $curveCV);  
    [/indent] }  
    else  
    {  
    [indent] error(“Curve Not Open”);  
    [/indent] }  
    }
    
    About the rebuild curve command. I think you have to rebuild the curve before you can query it, but I'm not sure.

After which, @Jhavna (Jhavna) added

    > About the rebuild curve command. I think you have to rebuild the curve before you can query it, but I'm not sure.
    
    Thanks for that snippet of script (is that a scrippet?)… anyhows…
    
    I tried that [quoted] but still get the same error. An explanation of why that command fails would be birlliant. I hate not knowing why something simply doesn't work when you follow the manual!

So @seven6ty (seven6ty) replied

    Thanks guys, I pretty much got it figured out now. I even got it far enough along to be able to make it so that I can first parent the nurbs curve's shape to a joint, to control that joint, and then take that shape and snap it to the duplicated nurbs curve:
    
    > global proc snapCurves()  
    >  {  
    >  // Select original object first, then the duplicate to snap the points to:  
    >  string $selected[] = `ls -sl`;  
    >  string $firstSelected[] = `listRelatives -type shape ($selected[0])`;  
    >  string $firstSel = $firstSelected[0];  
    >  string $secondSel = $selected[1];  
    >  if (`size $selected` > 2)  
    >  error(“Too many objects selected.”);  
    >  if (`size $selected` < 2)  
    >  error(“Please select two objects.”);  
    >  // Find how many CV points in the object:  
    >  int $maxCVs = `getAttr ($firstSel + ".spans")`;  
    >  // Snap points of first to the points of second:  
    >  int $x;  
    >  for ($x = 0; $x <= $maxCVs; $x++)  
    >  {  
    >  vector $loc = `xform -q -t -ws ($secondSel + ".cv[" + $x + "]")`;  
    >  // Move first selected object to second selected, vert by vert:  
    >  move -ws ($loc.x) ($loc.y) ($loc.z) ($firstSel + “.cv[” + $x + “]”);  
    >  }  
    >  }
    
    Only problem, sometimes, when I listRelatives for the $firstSel object, the skin cluster gets selected instead of my curve, anyone know how to stop that from happening??? So that I only get the names of the nurbs curves back, instead of all things that aren't transform nodes???

After which, @CGTalk_Moderation (CGTalk_Moderation) added

    This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.


{'source': 'discourse', 'url': 'https://forums.cgsociety.org/t/snapping-cv-points-of-one-obj-to-another/823421', 'title': 'snapping CV points of one obj to another?', 'views': 260, 'has_accepted_answer': False, 'word_count': 660, 'like_count': 0, 'reply_count': 2, 'participant_count': 4, 'posts': 6, 'tags': '', 'author': '@seven6ty (seven6ty)', 'participants': '@seven6ty (seven6ty), @Jhavna (Jhavna), @ajk48n (ajk48n), @CGTalk_Moderation (CGTalk_Moderation)', 'image_url': '', 'created_at': '2005-02-03T18:21:31.000Z', 'last_posted_at': '2006-02-04T16:00:01.000Z'}