I'm new at python and programming in general.
I'm currently use AutoCAD at work and am using python to generate scripts that require lots of repetition (drawing pipelines etc.
I am trying to figure out how to save the lines that are generated by my script to a text file.
I currently copy the items I see on the Python Shell to a text file.
I'm thinking what I need to do is somehow, generate a list and then output that list (maybe using the pickle module) to a text file. But I don't know how to automatically generate a list from my output.
If you reply, could you include code examples as I'm really just new at this and am having a rough time working out the details of the code.
I'm currently use AutoCAD at work and am using python to generate scripts that require lots of repetition (drawing pipelines etc.
I am trying to figure out how to save the lines that are generated by my script to a text file.
I currently copy the items I see on the Python Shell to a text file.
I'm thinking what I need to do is somehow, generate a list and then output that list (maybe using the pickle module) to a text file. But I don't know how to automatically generate a list from my output.
If you reply, could you include code examples as I'm really just new at this and am having a rough time working out the details of the code.
Code:
#Autolisp generator to generate list of AutoCommands to create a new layer in AutoCAD
#This line of code defines the Lisp Function
print '(defun C:layermaker()'
#This while loop creates a line of Lisp that creates a new layer named Color.
#The variable a is inserted into the string and then loops again.
#The resultant strings are currently copied from the Python Shell into a text file and then ran
#in AutoCAD. I would like the strings to be outputed to the text file.
a = 0
while a <= 256:
print '(COMMAND "-LAYER" "MAKE" "COLOR ',a, '" "COLOR" "',a,'" "" "")'
a = 1+a
# I was experimenting with writing to a file here.
fh = open('helloworld.txt', 'w')
fh.write('hello world 2')
fh.close()
Comment