Home Coding, Scripting, Shaders

Script Error Replacing the old model #MEL

polycounter lvl 8
Offline / Send Message
Pinned
jayantbhatt007 polycounter lvl 8
Hi, I'm working on a free Nut_Bolt script but I'm getting an error. Let's say I'm Importing the Bolt_01  it's snapping to the selected face but again when I run this script on a new selected face it's taking back Bolt_01 to the origin. It shouldn't happen like that. For more  REFER VIDEO.
 

{
// create a window
window -title "jay" -menuBar true -w 220 -h 200 "";
// define the layout of controls added
// to the window.
columnLayout;
// create a collapsible frame layout
frameLayout -collapsable true -label "Nuts";

// add the other controls
flowLayout -columnSpacing 1 -w 220 -h 30;
symbolButton -image "commandButton.png" -command "sample_Proc";

setParent ..;


// show the window we last created
showWindow;;
}

proc Pipe_01_Proc()
{
    string $sel_faces[] = `ls -sl `;
    string $file_Path = (`internalVar -userPrefDir`) + "icons/3DG_Nut/Mesh/Pipe_01.fbx";
    file -import $file_Path;
    rename "Pipe_01" "Pipe_01_Placed";
    select $sel_faces[0] "Pipe_01_Placed";
    float $rsScale = size($sel_faces);
    scale -r $rsScale $rsScale $rsScale "Pipe_01_Placed";
    string $rspointOnPolyConstraint[] = `pointOnPolyConstraint -offset 0 0 0  -weight 1 `;
    delete $rspointOnPolyConstraint;
    makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 -pn 1;
    makeIdentity -apply false -t 1 -r 1 -s 1;
    CenterPivot;
    xform -cpc;
   
}

https://www.youtube.com/watch?v=B9ao8VO8beI

Replies

  • Panupat
    Offline / Send Message
    Panupat polycounter lvl 17
    Because you're hard coding the bolt name "Bolt_01" but when you rename you are renaming "nut_01"
    What you need to do is to capture the actual name generated with the import
    string $current_bolt = `file -import "E:/Bolt_01.ma"`;
    And use $current_bolt for move/constraint/etc.

  • jayantbhatt007
    Offline / Send Message
    jayantbhatt007 polycounter lvl 8
    Panupat said:
    Because you're hard coding the bolt name "Bolt_01" but when you rename you are renaming "nut_01"
    What you need to do is to capture the actual name generated with the import
    string $current_bolt = `file -import "E:/Bolt_01.ma"`;
    And use $current_bolt for move/constraint/etc.

    Hi. when my file is .ma everything is fine but when I try to import fbx file format again I'm getting the same error and I changed the code as you said.
  • Panupat
    Offline / Send Message
    Panupat polycounter lvl 17
    Ah sorry I didn't try it with FBX. Apparently, importing .fbx does not return the object name the way .ma does so maybe hard coding the object name is the way to go.
Sign In or Register to comment.