Write 3dm file

Hi Steve
The below Python script don’t save a file 3dm. Where I went wrong?

import Rhino
file_3dm=Rhino.FileIO.File3dm()
print file_3dm
punto=Rhino.Geometry.Point3d(2,3,4)
p=file_3dm.Objects.AddPoint(punto)
a=file_3dm.Write("C:\BENACCHIO\as.3dm",5)
print file_3dm
print p
print a

Ciao Vittorio

[canceled]
Hmm, how do you actually REMOVE a post…?

Hi Mitch
I did not understand your question.
Ciao Vittorio

As far as I can tell right now, you ask a McNeel person to do it.

-Pascal

The path string has unescaped backslashes in it. In python (like many other languages), a backslash in a string means that you are defining a special character. For example

# the \n in the following string represents a newline character
s = "Two\nLines"

The way to create single backslashes in a string is to type \ \

So… to fix your script, change the line to

a = file_3dm.Write("C:\\BENACCHIO\\as.3dm",5)

Hi Steve
Perfect, all is OK. Grazie mille
Ciao Vittorio

I Steve
I can not find the method to add more items to the file:

#-*- encoding: UTF-8 -*-
import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs


file_3dm=Rhino.FileIO.File3dm() # qui creo l'oggetto file da salvare

print file_3dm
p1=Rhino.Geometry.Point3d(0,0,0) #creo i punti per disegnare la linea
p2=Rhino.Geometry.Point3d(10,10,30)
circle=Rhino.Geometry.Circle(p1,40)
circle2=Rhino.Geometry.Circle(p2,20)
line=Rhino.Geometry.Line(p1,p2)
# there is a method to add more objects?
p=file_3dm.Objects.AddLine(line) #creo la linea i metodi sono quelli di
                            # Rhino.DocObjects.Tables.(Add,Addarc,AddLine ecc.))
                            #oppure in scriptcontext.doc.objects.(Add,AddArc,AddLine ecc.)

a=file_3dm.Write("C:\\BENACCHIO\\as.3dm",5)

Ciao Vittorio

There are a bunch of different “Add” functions for the object table
http://4.rhino3d.com/5/rhinocommon/html/Methods_T_Rhino_FileIO_File3dmObjectTable.htm

Is there one in particular that you are having problems with?