Author Topic: Create a file then change block parameters  (Read 678 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Create a file then change block parameters
« 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.
« Last Edit: March 04, 2024, 02:17:26 AM by HasanCAD »

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Create a file then change block parameters
« Reply #1 on: March 04, 2024, 09:20:49 AM »
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...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Create a file then change block parameters
« Reply #2 on: March 05, 2024, 10:35:04 AM »
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.

Code: [Select]
(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
    )
)
« Last Edit: March 05, 2024, 10:45:21 AM by HasanCAD »

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Create a file then change block parameters
« Reply #3 on: March 05, 2024, 06:38:19 PM »
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.
A man who never made a mistake never made anything

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Create a file then change block parameters
« Reply #4 on: March 06, 2024, 02:17:13 AM »
The attached is Excel functions that can be used to code for your task.

Thanks Bigal

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Create a file then change block parameters
« Reply #5 on: March 06, 2024, 08:38:51 AM »
Main Objective: Modifying Block Parameters related to excel sheet Without Opening the File
« Last Edit: March 09, 2024, 04:16:25 AM by HasanCAD »

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Create a file then change block parameters
« Reply #6 on: March 09, 2024, 04:16:45 AM »
up

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Create a file then change block parameters
« Reply #7 on: March 09, 2024, 11:50:01 PM »
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 !!



A man who never made a mistake never made anything

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Create a file then change block parameters
« Reply #8 on: March 10, 2024, 05:23:15 AM »
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
)

kozmos

  • Newt
  • Posts: 114
Re: Create a file then change block parameters
« Reply #9 on: March 10, 2024, 11:07:46 AM »
No need that many steps, just two steps can do:
1) change current drawing
2) wblock whole drawing out to new filename
KozMos Inc.

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Create a file then change block parameters
« Reply #10 on: March 10, 2024, 06:54:07 PM »
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.
A man who never made a mistake never made anything