Hello!
I have a folder full of contour dxf, to open in rhino, but when I drope them in rhino, they are all in the same place: on the origin.
I would like to make a script that allows me to select the starting folder, and the script import all files one by one, I just have to move the files the width of the last between each import.
are they the commands to import a file, or list the files of a folder?
thank you!
can i use this type of code:
Dim filefolder
Set filefolder = FileSys.GetFolder(FolderPath)
Dim i as Integer
'loop through all files in the folder
For i = 1 To filefolder.Files.Count
Dim IFile
Set IFile = filefolder.Files.Item(i)
Hi, sorry I cannot help with vb, but this works in python:
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
from os import listdir
from os.path import isfile, join
path = "C:\\temp\\pyExport\\" #your file path (mind the double backslashes)
files = [f for f in listdir(path) if isfile(join(path, f))]
vec = rg.Vector3d(0,0,0)
if len(files)>0:
for f in files:
filename = path + f
rs.Command("! _-Import " + filename + " _Enter" + " _Enter")
g = rs.LastCreatedObjects()
rs.MoveObject(g, vec)
geo = rs.coercegeometry(g)
bbox = geo.GetBoundingBox(True)
vec = vec + (bbox.PointAt(1,0,0) - bbox.PointAt(0,0,0))
thank you David!!! but i don’t know Python, i would like but, i don’t have time to learn it…
to choose the file path, i use:
path= rs.BrowseForFolder(“C:\Program Files\” )???
You need double backslashes or a raw string (r”c:\windows\...”)
Thank you for sharing this piece of code. Tremendously helpfull for coding analphabetes like me.
I keep getting this error message. I’m sure there is an easy explanation, that I am just not aware of. Any idea?
When you see something like “None type has not… or cannot…” most likely some previous operation failed and what you think has data in fact does not (therefore it has a value of “None”).
In your case rs.LastCreatedObjects()
returns a list of objects (even if there is just one) or None
if nothing was created. Afterwards you use rs.MoveObject() which wants just one single object (GUID), but you have input either a list or None
, so it will most likely have failed and therefore return None
.
rs.coercegeometry
also requires just one object (GUID) as input , so it will most likely fail as well. Therefore when you try to get the bounding box of geo
(which is most likely 'None, that will fail because the function does not understand
None` as an input.
It’s handy to set a breakpoint in the debugger just before the line which fails and then check the values of all of your variables.
Thanks for taking the time to explain basic stuff!!
I will try to really understand what you wrote as soon as possible.