TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: HasanCAD on March 04, 2024, 02:01:47 AM
-
Hi All
We making shop drawing. and each item should be in separate file.
I created a block with parameters.
I am wondering is it possible to do these steps using Lisp
- Read data from excel file.
- Copy CAD from specific location.
- modify block parameters.
- close file.
File path: "C:\Library\xxx-xxxx-xxxx-xxxx-xx-xx.dwg"
New path: "C:\SD\xxx-xxxx-xxxx-xxxx-xx-xx.dwg"
Attached excel and CAD file.
Thanks in advance.
-
Is this for your homework, or this is pay job?
It looks pretty complex from an eye of novice... Have you just started beeing employee in some company working with drawings?
If you pay someone expirienced like Lee Mac and if he/she has time and if you are willing to pay for a favor I think your request woludn't be in group of vague relation... This way no one won't answer to your request/job...
-
Is this for your homework, or this is pay job?
You are absolutely right.
This is what I ended up to
I am wondering is it possible to edit the block related to excel sheet.
(if (and
(setq orgnlFile "C:\\ALFANAR_Standards\\AutoCAD\\Support\\Blocks\\StandardPanels\\260-01.dwg")
(setq destdir (LM:browseforfolder "Select a folder" "R:\\" 32))
(setq destdir (strcat destdir "\\260-01.dwg"))
(setq fso (vlax-create-object "Scripting.FileSystemObject"))
)
(progn
(vl-file-copy orgnlFile destdir T)
(vl-file-rename destdir "R:\\Hassan\\260-011.dwg" )
)
(alert "Not enough free space on the destination drive."))
;; Browse for Folder - Lee Mac
;; Displays a dialog prompting the user to select a folder.
;; msg - [str] message to display at top of dialog
;; dir - [str] [optional] root directory (or nil)
;; bit - [int] bit-coded flag specifying dialog display settings
;; Returns: [str] Selected folder filepath, else nil.
(defun LM:browseforfolder ( msg dir bit / err fld pth shl slf )
(setq err
(vl-catch-all-apply
(function
(lambda ( / app hwd )
(if (setq app (vlax-get-acad-object)
shl (vla-getinterfaceobject app "shell.application")
hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
)
(setq slf (vlax-get-property fld 'self)
pth (vlax-get-property slf 'path)
pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
)
)
)
)
)
)
(if slf (vlax-release-object slf))
(if fld (vlax-release-object fld))
(if shl (vlax-release-object shl))
(if (vl-catch-all-error-p err)
(prompt (vl-catch-all-error-message err))
pth
)
)
-
Yes can read a Excel file and update a dwg, because your opening an existing file as first step, would need to start the procedure as a script, which opens the master dwg, then runs lisps.
The attached is Excel functions that can be used to code for your task.
-
The attached is Excel functions that can be used to code for your task.
Thanks Bigal
-
Main Objective: Modifying Block Parameters related to excel sheet Without Opening the File
-
up
-
You can do the opposite and control autocad/Bricscad from Excel may be an easier way.
A good method suggested by others, uses one dwg the way was to import the dwg block into current dwg, explode etc, run the size changes etc then wblock as that lets you save with a new name. May sound silly but erase all, import block, set sizes , wblock. As its all happening in current dwg no need for a script.
I would have to check wether "saveas" will work also as that allows more scope like layouts with title block etc. Un tested !!
-
You can do the opposite
Sound is good
Let me give a try
What I do is
(while
- modify the current file
- QSave
- Copy the current file to new location
- Rename new file with new name
)
-
No need that many steps, just two steps can do:
1) change current drawing
2) wblock whole drawing out to new filename
-
I did suggest wblock in my post only disadvantage is that it takes only the entities selected not all the layers, other blocks, layouts etc that may be wanted in the new dwg.