Jump to content

Recommended Posts

Posted
F2 message,.......

 

Command: (LOAD "D:/Mijn documenten/CAD/Nieuwe map/RlxReadTitleBlock.LSP") bad argument type: stringp nil

Command: RlxReadTitleBlock

 

Processing 3 drawings...

Couldn't connect with drawing : D:\Mijn documenten\CAD\Nieuwe map\GH1-030-800.dwg

Couldn't connect with drawing : D:\Mijn documenten\CAD\Nieuwe map\GH1-030-750.dwg

Couldn't connect with drawing : D:\Mijn documenten\CAD\Nieuwe map\GH1-030-600.dwgbad argument type: VLA-OBJECT nil

Command:

 

If you get an error upon loading then there must something wrong at the start of the routine. If you load it from your visual lisp editor (type vlisp) and load it from there first use 'check lisp in editor' (tools pull down) , in the debug pull down set break on error. When the program stops you should be able to view the error trace (view pull down) and that would tell you which line the error occured. It seems like objectdbx is not functioning with you. I could rewrite the program to use a script but it would be a lot slower.

 

gr. Rlx

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • rlx

    15

  • pmxcad

    10

  • halam

    1

  • Silvano

    1

Top Posters In This Topic

Posted (edited)

First try if the odbx connection functions well by changing the init part

 

(defun RlxReadTitleBlock_Init (/ acVer)
 (vl-load-com)
 (setq acApp (vlax-get-acad-object) acDocs (vla-get-documents acApp) acVer (atoi (getvar "ACADVER")))
 (setq all-open (vlax-for dwg acDocs (setq all-open (cons (strcase (vla-get-fullname dwg)) all-open))))
 (setq objDBX (vl-catch-all-apply 'vla-getinterfaceobject (list acApp (if (< acVer 16)
       "objectdbx.axdbdocument" (strcat "objectdbx.axdbdocument." (itoa acVer))))))
 (if (or (void objDBX)(vl-catch-all-error-p objDBX))
   (progn (princ "\nUnable to connect to odbx")(setq objDBX nil))))

If it fails it should print 'unable to connect to odbx'

 

 

btw , you're not using autocad on a mac by any chance?

 

gr. Rlx

Edited by rlx
Posted (edited)

Ok , have rewritten routine to use a script instead of objectdbx , maybe this works

 



;----------------------------------------------------------------------------------------------------------------------
;    PmxCad
;    Written by Rlx - 1 feb 2016 for Jaap (PmxCad on CadTutor)
;    Search folders and subfolders for drawings for revision letter
;----------------------------------------------------------------------------------------------------------------------

(defun C:PmxCad ( / sourcefolder subfolder file filelist doc csv-name fp-csv scr-name fp-scr PmxCad-DclName
        SaveWithRevisionIsTrue)
 (setq sourcefolder (PmxCad_GetFolder "\nSelect source folder: ") SaveWithRevisionIsTrue (yesno))
 (foreach subfolder (getsubdirlist sourcefolder)
   (foreach file (vl-directory-files subfolder "*.dwg" 1)
      (if (wcmatch (strcase file t) "*.dwg")
    (setq filelist (cons (strcat subfolder "\\" file) filelist)))))
 (create_csv_file)
 (create_script_file)
 (if filelist (princ (strcat "\nProcessing " (itoa (length filelist)) " drawings..."))
   (princ "\nNo drawings were found..."))
 (if fp-scr
   (progn
     (foreach file filelist (PmxCad_AddToScriptFile (vl-string-translate "\\" "/" file)))
     (write_script_tail)))
 (if fp-scr (close fp-scr))(if fp-scv (close fp-scv))(gc)(gc)
 (if (and (not (void scr-name)) (findfile scr-name))
   (command "._script" scr-name) (princ "\nUnable to initiate script file"))
 (princ)
)


(defun PmxCad_SaveRevisionToCsvFile
      ( csv-name / doc valid-block-names layout obj attvalues blkname rev-list fp-csv)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 ; add additional titleblock names here
 (setq valid-block-names
    '("TITLE-BLOCK_A" "TITLE-BLOCK_A2" "TITLE-BLOCK_A1" "TITLE-BLOCK_A0" "IPW-ROH"))
 (vlax-for layout (vla-get-layouts doc)
   (vlax-for obj (vla-get-block layout)
     (if (and (eq "AcDbBlockReference" (vla-get-objectname obj))
          (member (setq blkname (strcase (vla-get-effectivename obj))) valid-block-names)
          (eq :vlax-true (vla-get-hasattributes obj)))
   (progn
     (setq attvalues (PmxCad_GetAttributeValues obj))
     (if (assoc "TKVRIJ6" attvalues)
       (progn
         ; it's possible multiple revisions will be found so save'm all in list
         (setq rev-list (cons (cdr (assoc "TKVRIJ6" attvalues)) rev-list))
       )
     )
   )
     )
   )
 )
 (if (void rev-list)(setq rev-list '("None")))
 (if (and (not (void csv-name)) (findfile csv-name) (setq fp-csv (open csv-name "a")))
   (mapcar '(lambda (x)(write-line (strcat (getvar "dwgname") "," x) fp-csv)) rev-list)
   (progn
     (princ "\nNo revisions were found")
     (princ "\nCsv file : ")(princ csv-name)
     (princ "\nfp-csv : ")(princ fp-csv)
     (princ "\nRev-list : ")(princ rev-list)
   )
 )
 (if fp-csv (close fp-csv))(gc)
 ;sort rev-list for latest revision and then save drawing with revision added to filename
 (if PmxCad-SaveWithRevisionLetter
   (progn (setq PmxCad-LastRev (last (vl-sort rev-list '> )))(PmxCad_SaveWithRevision)))
)

(defun void (x) (if (member x (list "" " " "  " "   " "    " nil '())) t nil))
(defun *error* (s) (princ s)(PmxCad_Exit))
(defun PmxCad_Exit () (princ "\nFoutje, bedankt.")(princ))

(defun PmxCad_GetAttributeValues (blk)
 (mapcar (function (lambda (att)(cons (vla-get-tagstring att)(vla-get-textstring att))))
     (vlax-invoke blk 'getattributes)))

(defun PmxCad_GetFolder (msg / sh objFolder objParentFolder strPath)
 (setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
 (setq objFolder  (vlax-invoke sh 'BrowseForFolder 0 msg 0 ""))
 (if objFolder 
  (and
    (setq strTitle (vlax-get objFolder "Title"))
    (setq objParentFolder (vlax-get objFolder 'ParentFolder))
    (setq strPath (vlax-get (vlax-invoke objParentFolder "Parsename" strTitle) "Path"))
    (vlax-release-object objParentFolder)
    (vlax-release-object objFolder))
  (vlax-release-object sh)
 )
 strPath
)

(defun GetSubDirList (strPath / lstDirectories)
 (setq lstDirectories (SearchSubDirectories strPath (list strPath))))

(defun SearchSubDirectories (strPath lstDirectories )
 (foreach strDirectory (vl-directory-files strPath nil -1)
   (if (not (member strDirectory (list "." ".." "...")))
     (progn
   (setq lstDirectories (cons (strcat strPath "\\" strDirectory) lstDirectories))
   (setq lstDirectories (SearchSubDirectories (strcat strPath "\\" strDirectory) lstDirectories)))))
 (reverse lstDirectories))


(defun create_csv_file ()
 (if (setq fp-csv
        (open (setq csv-name (vl-string-translate "\\" "/" (strcat sourcefolder "\\titleblocks.csv"))) "w"))
   (write-line (strcat "Filename" "," "Revision") fp-csv)
   (if (setq fp-csv (open (setq csv-name (strcat (getvar "savefilepath") "titleblocks.csv")) "w"))
     (write-line (strcat "Filename" "," "Revision") fp-csv)
     (progn (alert "Unable to create csv file")(exit)))))

(defun create_script_file ()
 (if (or (not (setq fp-scr (open (setq scr-name (strcat sourcefolder "\\PmxCad.scr")) "w")))
     (not (setq fp-scr (open (setq scr-name (strcat (getvar "savefilepath") "PmxCad.scr")) "w"))))
   (progn (alert "Unable to create script file")(exit))))

(defun write_script_tail ()
 (if (and fp-scr csv-name (findfile csv-name))
   (write-line (strcat "(shell_open \"" (vl-string-translate "\\" "/" (findfile csv-name)) "\")") fp-scr)
   (if fp-scr (write-line "(princ \"\nUnable to show csv file\")" fp-scr))))

(defun PmxCad_AddToScriptFile (dwg)
 (write-line "._Open" fp-scr)
 (write-line "(if (> (getvar \"dbmod\") 0)" fp-scr)
 (write-line (strcat "(command \"Yes\" \""  dwg "\")") fp-scr)
 (write-line (strcat "(command \""  dwg "\"))") fp-scr)
 (write-line "(while (= 1 (logand (getvar \"cmdactive\") 1))(command \"Yes\"))" fp-scr)
 (write-line "(load (findfile \"PmxCad.lsp\"))" fp-scr)
 (if SaveWithRevisionIsTrue
   (write-line "(setq PmxCad-SaveWithRevisionLetter t)" fp-scr)
   (write-line "(setq PmxCad-SaveWithRevisionLetter nil)" fp-scr))
 (if (and (not (void csv-name)) (findfile csv-name))
   (write-line (strcat "(PmxCad_SaveRevisionToCsvFile \"" csv-name "\")") fp-scr)
   (write-line "(princ \"\nCouldn't write revision to csv file - csf file not found\")" fp-scr))
)

(defun PmxCad_SaveWithRevision ( / dwg newdwg)
 (if (void PmxCad-LastRev)(setq PmxCad-LastRev "None"))
 (setq dwg (strcat (getvar "dwgprefix") (vl-filename-base (getvar "DWGNAME")))
   newdwg (strcat dwg "-" PmxCad-LastRev ))
 (setvar "FILEDIA" 0)(setvar "EXPERT" 5)
 (if (= (getvar "writestat") 1)
   (progn (command "._saveas" "" newdwg)(vl-file-delete (strcat dwg ".dwg")))
   (progn
     (princ (strcat "\nNo write permission in " (vl-filename-directory newdwg)))
     (princ "\nNew dwgname : ")(princ newdwg)
   )
 )
 (setvar "FILEDIA" 1)(setvar "EXPERT" 0)
 (princ)
)


(defun yesno ( / dialog )
 (CreateYesNoDcl)
 (if (setq dialog (load_dialog PmxCad-DclName))
   (progn
     (new_dialog "yesno" dialog)
     (action_tile "accept" "(done_dialog 1)")(action_tile "cancel" "(done_dialog 0)")
     (setq drv (start_dialog))(unload_dialog dialog)(vl-file-delete PmxCad-DclName)))
 (if (= drv 1) t nil)
)

(defun CreateYesNoDcl ( / fp)
 (if (setq fp (open (setq PmxCad-DclName (strcat (getvar "savefilepath") "yesno.dcl")) "w"))
   (write-line "yesno : dialog { label = \"Add revision letter to drawing name ?\"; ok_cancel;}" fp)) (if fp (close fp))(gc))

(defun shell_open ( target / shell result )
 (if (and (or (eq 'INT (type target)) (setq target (findfile target)))
      (setq shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")))
   (progn
     (setq result (vl-catch-all-apply 'vlax-invoke (list shell 'open target)))
     (vlax-release-object shell)(not (vl-catch-all-error-p result)))))

(princ "\nPmxCad by RLX 1 feb 2016")
(princ)

Code is reasonable idiot-proof but then again... ;-)

 

Just one thing , set SDI to 1 before running the program. Save routine as PmxCad.lsp in one of your support paths , load it and start with PmxCad.

 

Good luck

 

gr. Rlx

Edited by rlx
Posted

Wow Rlx it`s working.

A question: the lisp makes a empty script file, why?

And is it possible to make a change to the lisp, if there is no Revision letter in the drawing/attribute, let the file name as it is instead of "none"

Is it easy to split the two functions (drawinglist/rename) in two seperated lisps?

It looks to sub folders, can this be disabled?

 

PmxCAD

Posted (edited)
Wow Rlx it`s working.

A question: the lisp makes a empty script file, why?

And is it possible to make a change to the lisp, if there is no Revision letter in the drawing/attribute, let the file name as it is instead of "none"

Is it easy to split the two functions (drawinglist/rename) in two seperated lisps?

It looks to sub folders, can this be disabled?

 

PmxCAD

 

Hi Jaap,

 

First making an empty script is just part of testing for write acces. If this test fails there's no use in letting the program do it's thing. Will have look 2morrow if you can just remove the 'none' part , don't think it's any problem (just not in the mood to do it now). As far as the rename part , simply press cancel when asked if you want to rename the files aswell. And of cource it's possible to remove the subfolder part or I could let the program ask if you want to. I'll be back...

 

 

 

 

Honey I'm back... icon14.gif (update 3 feb) :

 

gr. Rlx

PmxCad.LSP

Edited by rlx
  • 5 years later...
Posted

Hi, I saw this post and it's exactly what I need, unfortunately it doesn't work yet.. Titleblock is Stempel_NP and attribute ADRES-A which should be modified. Have modified this in the lsp file but it does not work. anyone have any tips? Very much appreciated.

Posted

Untested (you didn't post a sample drawing to test on) but try attached version. When comparing strings (like block- or attribute names) always make sure they have the same case (upper or lower case).

 

🐉

Silvano.LSP

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...