Hi, I was looking to get help on a problem I've been having with using the "Insert" function in Rhinoscript. So far, I have:

Rhino.Command "-Insert F=Yes Z:\Rhino\Block B 0,0,0 2.1 0"

where I specify the file location of the Block I am inserting, "B" indicates that it is a Block, "0,0,0" is the insert point, "2.1" is the scale, and "0" is the rotation.
This works but isn't exactly what I want. I was looking to use variables to describe the insert point, scale, and rotation. So something more like this (which doesn't work):

arrInsertPoint = Array(0,0,0)
arrScale = Array(2.1)
arrRotate = Array(0)
Rhino.Command "-Insert F=Yes Z:\Rhino\Block B arrInsertPoint arrScale arrRotate"

I realize this seems arbitrary but it's actually necessary due to the fact that this code will be implemented by Model Center which allows the user to alter the variables from its interface. Of course the code doesn't have to look a certain way, just perform the same task. If anyone could give any advice or hints on how I could go about this, I would greatly appreciate it.

Thanks,
Josh

Views: 929

Replies to This Discussion

Hi Josh,

Rhino.Command require a string. In your example, arrInsertPoint is not a string but an array. Thus, you will have to format a string from the contents of the array and concatenate it to the base string. Likewise with arrScale and arrRotate.

 

For example:

 

strFile = "Z:\Rhino\Block"
strBlock = "B"
arrPoint = Array(0,0,0)
dblScale = 2.1
dblRotate = 0

strCmd = "_-Insert _File=_Yes "
strCmd = strCmd & Chr(34) & strFile & Chr(34) & " "
strCmd = strCmd & Chr(34) & strBlock & Chr(34) & " "
strCmd = strCmd & Rhino.Pt2Str(arrPoint) & " "
strCmd = strCmd & CStr(dblScale) & " "
strCmd = strCmd & CStr(dblRotate) & " "
MsgBox strCmd

Call Rhino.Command(strCmd)

Note, the Chr(34) statements add double-quote characters round the string (in case the string has space characters).

Let me know if this helps.

 -- Dale

 

Hi Dale,

I have one problem with _-Insert  and RunScript. 

This is part of my code:

using (StreamReader reader = new StreamReader(filename))

{
     string line;

     while ((line = reader.ReadLine()) != null)
     {
          string[] substrs = line.Split(';');

          if (substrs[0].Equals("package"))
          {
               string modelFilename = modelPath + substrs[6] +".3dm";
               if (!System.IO.File.Exists(modelFilename))
               {
                    Rhino.RhinoApp.WriteLine("File {0} not found.", modelFilename);
                    continue;
               }
               string script = string.Format("_-Insert _File=_Yes \"{0}\" B {1},{2},{3} {4} {5}

                                                      _Enter", modelFilename, 0, 0, 0, 1, 0);
               Rhino.RhinoApp.WriteLine(script);
               Rhino.RhinoApp.RunScript(script, true);
          }

     }
}

I need to parse text file with component position, rotation and name. But when I start my import plugin nothing happens. In Rhino command line I can see result of this Rhino.RhinoApp.WriteLine(script); and it looks OK to me 

_-Insert _File=_Yes "C:/models/R0805.3dm" B 0,0,0 1 0 _Enter

And also when I copy this string into command line It will insert part R0805.3dm to position 0,0,0. 

I would like to ask you If the problem could by with execution speed of commands. Because when I ran this string in cmd line i takes some time to finish??

thanks 

martin

RSS

Translate

© 2019   Created by McNeel Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service