script for piping

Help
Brian
2011-12-13
2013-04-22
  • Brian

    Brian - 2011-12-13

    I am trying to add a bunch of wiring harnesses and cables using a tcl script, the pipe command, and a csv file.  I am having difficulty getting BRL-CAD to build the pipe primitive.

    I have tried to do a loop that concatenates the the command "in name pipe x1 y1 z1 id1 od1 r1 x2 y2 z2 id2 od2 r2 …. xn yn idn odn rn"

    Approach 1: my final command in the tcl script is "$command", where command contains "in name pipe…. " I get this error:
    "invalid command name "in test.s1 pipe 2 0 0 0 0 0.125 1 0 10 0 0.125 1"

    Approach 2: final command in the tcl script is "in  $solid_name pipe $num_points $command" where command is an appended string of the geometric info, I get this error: "more arguments needed::Enter Y:"

    However for both cases if I do a "puts" then the command… and copy and paste the output.  BRL-CAD generates the proper geometry.  So the syntax for the "in" command seems to be fine.  It seems to more how BRL-CAD handles the tcl script.

    Any thoughts on how to approach it?

    Here is the code… admittedly, it's probably a bit sloppy.

    Approach 1

    # Import File Info
    set infile [open {c:\user\cables.csv} r]
    set delim ","
    set num_headers 1;
    # Set units to inches
    units in
    set line_num 1; # initializes the file line count
    set point_num 1; # initializes the pipe point count
    set command "in "
    while { [gets $infile instring] >= 0 } {
        # If statement, causes script to skip header row
        if  { $line_num > $num_headers } {
            set inlist [split $instring $delim]; # split input from file
            set color_code [lindex $inlist 0]; # Get system color code
            set sub_sys [lindex $inlist 1]; # Get sub_system
            set region_id [lindex $inlist 2]; # Get region ident number
            set name [lindex $inlist 3]; # Get name description
            set matl [lindex $inlist 4]; # Get material
            set num_points [lindex $inlist 5]; # number of points for cable/pipe
            set i_dia [lindex $inlist 6]; # Get inner diameter of pipe (cables = 0)
            set o_dia [lindex $inlist 7]; # Get outer diameter of pipe/cable
            set radius [lindex $inlist 8]; # Get the bend radius
    
            # Get the coordinates for the Vertex of the pipe/cable
            set xvert [lindex $inlist 9]
            set yvert [lindex $inlist 10]
            set zvert [lindex $inlist 11]
    
            # Primitive names
            set solid_name $name
            append solid_name ".s1"
            set part $name
            append part ".r";
    
            # Generate Cable/Pipe Geometry
            # X, Y, Z, inner diameter, outer diameter, and bend radius for point __ 
            if { $point_num == 1} {
                # first point of new pipe
                append command "$solid_name pipe $num_points $xvert $yvert $zvert $i_dia $o_dia $radius "
                incr point_num
    
            } elseif { $num_points == $point_num } {
                # last point of pipe
                append command "$xvert $yvert $zvert $i_dia $o_dia $radius"
                $command
                set command ""; # reset command
                set point_num 1; # reset point_num
    
                # Generate Regions
                r $part u $solid_name
    
                # Assign properties to shell
                attr set $part material_id $matl
                attr set $part region_id $region_id
                attr set $part color $color_code
    
                # Put in Assembly
                g $sub_sys $part
    
            } else {
                # intermediate point
                append command "$xvert $yvert $zvert $i_dia $o_dia $radius "
                incr point_num
            }
    
        }
        # Increment line number
        incr line_num
    }
    # Close File
    close $infile
    

    Approach 2

    # Import File Info
    set infile [open {c:\user\cables.csv} r]
    set delim ","
    set num_headers 1;
    # Set units to inches
    units in
    set line_num 1; # initializes the file line count
    set point_num 1; # initializes the pipe point count
    set command ""
    while { [gets $infile instring] >= 0 } {
        # If statement, causes script to skip header row
        if  { $line_num > $num_headers } {
            set inlist [split $instring $delim]; # split input from file
            set color_code [lindex $inlist 0]; # Get system color code
            set sub_sys [lindex $inlist 1]; # Get sub_system
            set region_id [lindex $inlist 2]; # Get region ident number
            set name [lindex $inlist 3]; # Get name description
            set matl [lindex $inlist 4]; # Get material
            set num_points [lindex $inlist 5]; # number of points for cable/pipe
            set i_dia [lindex $inlist 6]; # Get inner diameter of pipe (cables = 0)
            set o_dia [lindex $inlist 7]; # Get outer diameter of pipe/cable
            set radius [lindex $inlist 8]; # Get the bend radius
    
            # Get the coordinates for the Vertex of the pipe/cable
            set xvert [lindex $inlist 9]
            set yvert [lindex $inlist 10]
            set zvert [lindex $inlist 11]
    
            # Primitive names
            set solid_name $name
            append solid_name ".s1"
            set part $name
            append part ".r";
    
            # Generate Cable/Pipe Geometry
            # X, Y, Z, inner diameter, outer diameter, and bend radius for point __ 
            if { $point_num == 1} {
                # first point of new pipe
                append command "$xvert $yvert $zvert $i_dia $o_dia $radius "
                incr point_num
    
            } elseif { $num_points == $point_num } {
                # last point of pipe
                append command "$xvert $yvert $zvert $i_dia $o_dia $radius"
                # puts "$solid_name pipe $num_points $command "
                in $solid_name pipe $num_points $command
                set command ""; # reset command
                set point_num 1; # reset point_num
    
                # Generate Regions
                r $part u $solid_name
    
                # Assign properties to shell
                attr set $part material_id $matl
                attr set $part region_id $region_id
                attr set $part color $color_code
    
                # Put in Assembly
                g $sub_sys $part
    
            } else {
                # intermediate point
                append command "$xvert $yvert $zvert $i_dia $o_dia $radius "
                incr point_num
            }
    
        }
        # Increment line number
        incr line_num
    }
    # Close File
    close $infile
    
     
  • Brian

    Brian - 2011-12-13

    I needed an:

    eval _____

     
  • Sean Morrison

    Sean Morrison - 2011-12-14

    I'd recommend the first approach where you build up the command, then eval the command.  Glad to hear you figured out that latter detail.  That has more to do with the fact that the mged command line is also an interactive Tcl interpreter and that is Tcl's behavior to require the eval.

    Cheers!
    Sean

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks