Jump to content

Recommended Posts

Posted

 Its looking like coreconsole cannot run the purge command (unknown command error), which is a big part of what i wanted to do.

I have found this link 

https://www.theswamp.org/index.php?topic=31867.msg373489#msg373489

but it isnt lisp, can this be run within lisp ?.

 

 

Posted

i have a routine that cleans up drawings (dpsr), it runs great when included in a script.

trying to use it with core console i get:-

 image.png.5b5f870a9622f18316e883ffffbdb2bf.png

the lisp code for dpsr is :-

;;//////////////////////////////////////////////////
;; checkcolor

(defun CheckEntColor (ent / entData color layer layerData layerColor)
  (setq entData (entget ent))
  (setq color (cdr (assoc 62 entData)))
  (cond
    ((and color (/= color 256) (>= color 5)) T)
    ((or (not color) (= color 256))  (setq layer (cdr (assoc 8 entData)))  (setq layerData (tblsearch "LAYER" layer))   (setq layerColor (cdr (assoc 62 layerData))) (if (and layerColor (>= layerColor 5)) T nil))
    (T nil)
  )
)

(defun c:dpsr (/	    doc		 ms	      result
	       layers-ok    ltypes-ok	 ents-ok      props-ok
	       layer-errors ltype-errors enttype-errors
	       prop-errors  csv-line	 ename	      clr
	       lt	    lyr
	      )

  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq ms (vla-get-modelspace doc))
  (setq	*audit-csv-path* (strcat (getvar "DWGPREFIX") "DWG_Audit_Report.csv"))

  ;; CSV functions
  (defun append2csv (line / file)
    (setq file (open *audit-csv-path* "a"))
    (if	file
      (progn (write-line line file) (close file))
      (prompt "\nERROR: Cannot write to audit CSV.")
    )
  )

  (defun writecsvheader	()
    (if	(not (findfile *audit-csv-path*))
      (append2csv
	"DWGNAME,LAYERSTATES,LINETYPES,ENTITYTYPES,ENTITYDEF,LAYER-ERRS,LT-ERRS,TYPE-ERRS,PROP-ERRS"
      )
    )
  )
;;////////////////////////////////////////////////////////
  ;; Create or set a layer
  (defun makelayer (name color lw tran ltype)
    (if	(not (tblsearch "layer" name))
      (vla-add (vla-get-layers doc) name)
    )
    (vla-put-color (vla-item (vla-get-layers doc) name) color)
    (vla-put-lineweight (vla-item (vla-get-layers doc) name) lw)
    (command "-layer" "tr" (rtos tran 2 0) name "")
    (command "-layer" "l" ltype name "")
  )

  ;; Explode blocks
  ;;(vlax-for ent	ms
  ;;  (if	(and (= "AcDbBlockReference" (vla-get-objectname ent))
	;;     (vlax-method-applicable-p ent 'explode)
	;;)
      ;;(vla-explode ent)
    ;;)
  ;;)
(defun explodeall ( / explode layouts )
   (setq layouts (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
         explode t
   )
   (while explode
       (setq explode nil)
       (vlax-for layout layouts
           (vlax-for obj (vla-get-block layout)
               (and
                   (= "AcDbBlockReference" (vla-get-objectname obj))
                   (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-explode (list obj))))
                   (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-delete  (list obj))))
                   (setq explode t)
               )
           )
       )
   )
   ;(princ)
)
(explodeall)


  ;; Create layers
  (makelayer "D-3D-SOL" 7 30 0 "Continuous")
  (makelayer "D-3D-CLG" 1 18 0 "Center")
  (makelayer "D-3D-CLM" 5 18 0 "Center")
  (makelayer "0" 7 -1 0 "Continuous")

 ;; catch all to make sure everything is set ok if not created by makelayer fuction
 ;; Set current layer to sol
  (command "_.layer" "_set" "D-3D-SOL" "")
  (command "_.layer" "_c" "7" "" "")
  (command "_.layer" "_tr" "0" "" "")
  (command "_.layer" "_lw" "0.3" "" "")
  (command "_.layer" "_l" "Continuous" "" "")

 ;; Set current layer to clm
  (command "_.layer" "_set" "D-3D-CLM" "")
  (command "_.layer" "_c" "5" "" "")
  (command "_.layer" "_tr" "0" "" "")
  (command "_.layer" "_lw" "0.18" "" "")
  (command "_.layer" "_l" "Center" "" "")

 ;; Set current layer to clg
  (command "_.layer" "_set" "D-3D-CLG" "")
  (command "_.layer" "_c" "1" "" "")
  (command "_.layer" "_tr" "0" "" "")
  (command "_.layer" "_lw" "0.18" "" "")
  (command "_.layer" "_l" "Center" "" "")

;; Set current layer to 0
  (command "_.layer" "_set" "0" "")
  (command "_.layer" "_c" "7" "" "")
  (command "_.layer" "_tr" "0" "" "")
  (command "_.layer" "_lw" "0.25" "" "")
  (command "_.layer" "_l" "Continuous" "" "")


  ;; Error counters
  (setq	layer-errors   0
	ltype-errors   0
	enttype-errors 0
	prop-errors    0
  )

  ;; Process objects
  (vlax-for ent	ms
    (setq ename	(vla-get-objectname ent)
	  clr	(vla-get-color ent)
	  lt	(vla-get-linetype ent)
	  lyr	(vla-get-layer ent)
    )

    ;; Classification and move to appropriate layer
    (cond
      ((wcmatch ename "AcDb3dSolid,AcDbSurface")
       (vla-put-layer ent "D-3D-SOL")
      )
      ((and (member ename '("AcDbLine" "AcDbPolyline" "AcDbCircle" "AcDbArc"))
	    (not (CheckEntColor (vlax-vla-object->ename ent)))             ;; Was (not (CheckEntColor ent))
       )
       (vla-put-layer ent "D-3D-CLG")
      )
      ((and (member ename '("AcDbLine" "AcDbPolyline" "AcDbCircle" "AcDbArc"))
	    (CheckEntColor (vlax-vla-object->ename ent))
       )
       (vla-put-layer ent "D-3D-CLM")
      )
    )

    ;; Set ByLayer color and linetype
    (if	(/= clr 256)
      (progn (vla-put-color ent 256)
	     (setq prop-errors (1+ prop-errors))
      )
    )
    (if	(/= (strcase lt) "BYLAYER")
      (progn (vla-put-linetype ent "BYLAYER")
	     (setq prop-errors (1+ prop-errors))
      )
    )

    ;; Track invalid types and linetypes
    (if	(not (member ename
		     '("AcDbLine"	  "AcDbPolyline"
		       "AcDbCircle"	  "AcDb3dSolid"
		       "AcDbSurface"      "AcDbArc"
		      )
	     )
	)
      (setq enttype-errors (1+ enttype-errors))
    )
    (if	(not
	  (member (strcase lt) '("BYLAYER" "CONTINUOUS" "CENTER"))
	)
      (setq ltype-errors (1+ ltype-errors))
    )
  )

  ;; Delete entities on layer "0"
  (vlax-for ent	ms
    (if	(= (strcase (vla-get-layer ent)) "0")
      (vla-delete ent)
    )
  )

  ;; Set layer 0 current
  (vla-put-activelayer
    doc
    (vla-item (vla-get-layers doc) "0")
  )

  ;;Remove duplicates
  (command "-OVERKILL" "ALL" "" "")
 
  ;; Purge all
  (repeat 3 (command "_.PURGE" "ALL" "*" "N"))
  (repeat 2 (command "_.PURGE" "Regapps" "*" "N"))

  ;; Set UCS/view
  (command "_.UCS" "_W")
  (command "_.-VISUALSTYLES" "C" "_CONCEPTUAL") ;; Fixed
  (command "_.VIEW" "_SWISO")
  (command "_.ZOOM" "_E")

  ;; Final checks
  (setq	layers-ok (and (tblsearch "layer" "0")
		       (tblsearch "layer" "D-3D-SOL")
		       (tblsearch "layer" "D-3D-CLG")
		       (tblsearch "layer" "D-3D-CLM")
		  )
  )

  ;; Build CSV output
  (setq	result
	 (strcat (getvar "DWGNAME")
		 ","
		 (if layers-ok
		   "PASS"
		   "FAIL"
		 )
		 ","
		 (if (= ltype-errors 0)
		   "PASS"
		   "FAIL"
		 )
		 ","
		 (if (= enttype-errors 0)
		   "PASS"
		   "FAIL"
		 )
		 ","
		 (if (= prop-errors 0)
		   "PASS"
		   "FAIL"
		 )
		 ","
		 (itoa layer-errors)
		 ","
		 (itoa ltype-errors)
		 ","
		 (itoa enttype-errors)
		 ","
		 (itoa prop-errors)
	 )
  )

  (writecsvheader)
  (append2csv result)

 

the script i am using to run it is:-

(load "C:/Users/me/LIBRARY/AutoCad/AutocadScripts/dwgprocessor.lsp")
dpsr
qsave
close

 

and the batch file used to run the scrpit is:-

 

@echo off
setlocal
:: Set the path to the folder containing your DWG files
set "folderpath=C:\Users\me\ASSETS\DWG\3D\LIGHT"
:: Set the AutoCAD Core Console executable path
set "AutoCADCoreConsole=C:\Program Files\Autodesk\AutoCAD 2026\accoreconsole.exe"
:: Set the path to your LISP file
set "lispFile=C:\Users\me\LIBRARY\AutoCad\AutocadScripts\process.scr"
:: Loop through all DWG files in the folder
for %%f in ("%folderPath%\*.dwg") do (
    echo Processing: %%f
    "%AutoCADCoreConsole%" /i "%%f" /s "%lispFile%" /product ACAD /l en-US
)
endlocal

 

when run, dpsr is basically ignored and the next two lines of the script are run:-

image.png.cb0f751860ede6f5f18b34a2ea6b3d27.png

 

is it the VL commands causing the issue ?

.

 

Posted

Core Console returns nil for (vlax-get-acad-object).

Posted

Core console doesn't generally like VLA- commands, if you can do it all in pure LISP then you have more success.

Posted

Thank you .

I have set things running on another pc, I was hoping to save some time .

interesting to learn about core console though .

 

 

  • Like 1
Posted

you could try loading the visual lisp functions in your script (never tested it myself thou..)

 

 

http://www.theswamp.org/index.php?topic=57471.msg609440#msg609440

 

Quote from: VovKa on March 29, 2022, 11:45:12 AM
Quote from: jmcshane on March 29, 2022, 09:03:29 AM
I'm thinking it might be based on ActiveX which isn't supported in acoreconsole as far as I know.
(layoutlist) is defined inside acapp.arx which is not loaded by acoreconsole

So simply load it in the Script:

Code: [Select]
_.arx L "acapp.arx"
(setq foo (layoutlist))

Core Console supports loading ARX/.NET assemblies.

 

Posted
14 hours ago, rlx said:

you could try loading the visual lisp functions in your script (never tested it myself thou..)

 

 

http://www.theswamp.org/index.php?topic=57471.msg609440#msg609440

 

Quote from: VovKa on March 29, 2022, 11:45:12 AM
Quote from: jmcshane on March 29, 2022, 09:03:29 AM
I'm thinking it might be based on ActiveX which isn't supported in acoreconsole as far as I know.
(layoutlist) is defined inside acapp.arx which is not loaded by acoreconsole

So simply load it in the Script:

Code: [Select]
_.arx L "acapp.arx"
(setq foo (layoutlist))

Core Console supports loading ARX/.NET assemblies.

 

Ha! You quoted everyone but me. 

Posted

Ow sorry , not intentionally , assumend peoples would click on swamp link and see that this came from

 

BlackBox BlackBox BlackBox :celebrate:

  • Funny 1
Posted
3 hours ago, rlx said:

Ow sorry , not intentionally , assumend peoples would click on swamp link and see that this came from

 

BlackBox BlackBox BlackBox :celebrate:

Kind of you to say, now I'm blushing. LoL

 

I'm just passionate about Core Console, and think it's one of the best 'new' features in the last decade+, that's seemingly underutilized (as I understand it from forum convos, etc). 

 

Cheers

  • Like 1
Posted

I cannot use purge with coreconsole.

i get a unknown command error.

the link sent earlier lists purge as a valid command ??

Posted
40 minutes ago, jamami said:

I cannot use purge with coreconsole.

i get a unknown command error.

the link sent earlier lists purge as a valid command ??

 

What happens when you invoke -PURGE instead?

Posted

Thank you BlackBox  - it works!

 

still doesn't like and visual lisp though :(

 

Posted
19 minutes ago, jamami said:

Thank you BlackBox  - it works!

 

still doesn't like and visual lisp though :(

 

Happy to help!

 

TLDR; if you haven't already, post your code, as most of what you're wanting to do can be done using OOTB Commands via Core Console & .SCR file.

 

Where that falls short, Core Console support NETLOAD & ARX Commands to load assemblies, which basically expose the entire .NET & ARX APIs. 

 

HTH

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...