nick777 Posted February 14, 2013 Posted February 14, 2013 I stole this code from someone and modified it. It's probably insanely inefficient, but I barely know what I'm doing. Anyway, what it does is inserts a bunch of blocks from my block library into a drawing. I'm sure someone has a 10-line code for this, that I'd happily steal. I'd like to be able to change this so that I can run it as a command with a script because I have a few other code blocks that I'm running with a script and I'd like to add this one. How can I mod this? (defun open_dbx (dwg / dbx) (if (< (atoi (substr (getvar "ACADVER") 1 2)) 16) (setq dbx (vlax-create-object "ObjectDBX.AxDbDocument")) (setq dbx (vlax-create-object (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2))))) (vla-open dbx dwg) dbx ) ;Get "Valve" in 'ValveBlock_TapCard.dwg" file : (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/ValveBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "Valve"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up ;Next block import (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/ManholeBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "Manhole"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up ;Next block import (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/BuildingBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "Building"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up ;Next block import (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/CurbValveBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "CurbValve"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up ;Next block import (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/GateValveBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "GateValve"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up ;Next block import (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/HydrantBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "Hydrant"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up ;Next block import (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/MeterPitBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "MeterPit"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up ;Next block import (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/NArrowBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "NorthArrow"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up ;Next block import (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/PoleBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "Pole"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up ;Next block import (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/StreetNameBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "StreetName"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up ;Next block import (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/TapCardNumberBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "TapCardNumber"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up ;Next block import (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/WallBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "Wall"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up ;Next block import (setq Dbx (open_dbx "I:/Water_CAD_Details/TAP_BlockLibrary/WaterMainBlock_TapCard.dwg")) ; file name containing block (vla-CopyObjects Dbx (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks dbx) "WaterMain"))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (vlax-release-object dbx) ;Clean-up Quote
BIGAL Posted February 15, 2013 Posted February 15, 2013 We dont steal code we borrow ! I wouldn't do it the way in the code rather just have a list of blocks or a text file and 1 defun to do the insert part like you say 10 lines, if you want to do as a script just write down 1 line of the necessary command steps and copy and change block name save as a script. Quote
nick777 Posted February 15, 2013 Author Posted February 15, 2013 I don't know how to use a script to run this. I have one that runs another lisp, and it has a command "tapconvert." How do I get a command so I can preload this script then run it with a script a bunch of times? I tried adding C: before open_dbx but that doesn't work. I want to change this so I can run it as a script, but I don't know how to either change it or get the script to open and run it. Quote
nick777 Posted February 15, 2013 Author Posted February 15, 2013 I don't know how to use a script to run this. I have one that runs another lisp, and it has a command "tapconvert." How do I get a command so I can preload this script then run it with a script a bunch of times? I tried adding C: before open_dbx but that doesn't work. I want to change this so I can run it as a script, but I don't know how to either change it or get the script to open and run it. I just added all this into the other lisp. Can't figure out how to get it to run in a script but that one will because the C: works. Unfortunately, I cannot figure out how to do the list thing you speak of, but it sounds good in theory =P Quote
BIGAL Posted February 16, 2013 Posted February 16, 2013 example of a script just type script open dwg1 z e insert block1 0,0 1 1 0 insert block2 0,0 1 1 0 insert block3 z e close y open dwg2 z e insert block1 0,0 1 1 0 insert block2 0,0 1 1 0 insert block3 z e close y and so on Quote
nick777 Posted February 19, 2013 Author Posted February 19, 2013 example of a script just type script open dwg1 z e insert block1 0,0 1 1 0 insert block2 0,0 1 1 0 insert block3 z e close y open dwg2 z e insert block1 0,0 1 1 0 insert block2 0,0 1 1 0 insert block3 z e close y and so on I was using AutoScript because it lets you select folders full of files and I have something like 12,000+ to run it on. So I want the script to apply to all those files, which AScript takes care of, then run a few .lsp's. I can preload ones that run with a command, but if it doesn't have that C: to set something to run as a command, I don't know how to get the script to run it. There appears to be like zero documentation on scripts anywhere... I have the ACAD Bible and the internet, but really don't see much. I know it's something simple, but just don't know the syntax. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.