Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vba code for CAD simple code gone wrong need advice!

Status
Not open for further replies.

Shaun29

Programmer
Oct 22, 2008
53
US
I am Trying to write a simple code to extract attribute info from a block. I want to use this block for all my CAD drawings, despite that the may be different and compile all info on to one text file.

I Am running CAD 2007
so I created a BOM with attributes I created a template using EATTEXT, Next I used ATTEXT to extract a TEST sample of attribute information.

Problem when I extract and replace information my template is not updating with new text i input and my output file is blank. after i select an save and extract the changes to the block.
I am also getting an error:
Invalid field specification: (then it shows a jumbled up order of my tags. that doesnt match that of the template.

The Blocks name is BOM_TEXT.dwg
The OUTPUT (that is Blank) is called outputbom.txt
The Template I created is called templatebom.txt

now the code I VBARUN and created

Sub BOM()
open "BOM_TEXT.dwg" as output #1
write #1, "txt.outputbom.txt" eof(1)
end
end sub

I eof so all new blocks i oped will add new text from block to the end of the last text.

any sugestions or corrections?
 

Code:
Sub BOM()

Open "BOM_TEXT.dwg" [blue]For Append As[/blue] #1
Write #1, "txt.outputbom.txt" eof(1)
[blue]Close #1[/blue]

End sub


Have fun.

---- Andy
 
it is saying permission denied and steps to the append line.
would output work?
 

You need a full path with the file name in Open statement, something like:

Open "C:\SomeFolder\BOM_TEXT.dwg" For Append As #1

This way any new info will be added to the end of BOM_TEXT.dwg, if you use For Output, every time you run it it will create a new file with the text you write into it.


Have fun.

---- Andy
 
this is my code but it keeps telling me "permision denied" is it an application write protect? or a permisions? issue error code 70 any ideas?

Sub BOM()
Open ("C:\Users\sp\Documents\Bill of Material text transfer\BOM MACRO\Bomblock.dwg") For Append As #1
Write #1, ("txt.bomtest.txt"); EOF(1)
Close #1
End Sub
 

Instead of going after you file:

C:\Users\sp\Documents\Bill of Material text transfer\BOM MACRO\Bomblock.dwg

Try something simple like:

C:\Text.txt

and see if your code will work OK with no error.

Have fun.

---- Andy
 
Perhaps this?

file number
Number used in the Open statement to open a file. Use file numbers in the range 1–255, inclusive, for files not accessible to other applications. Use file numbers in the range 256–511 for files accessible from other applications.
 
not working does the file am trying to accsess have to open or closed
 

If you want to Open, the File has to be closed. You can not open the file that is used (open) by other application.

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top