Jump to content

Recommended Posts

Posted

I was trying to see if I could hatch objects inside a block with a solid hatch.

 

Any help would be appreciated.

 

Here's what I have so far:

(defun c:test (/ ss1 blkn cnt var_cmdecho)

  (prompt "\nSelect blocks to hatch with solid hatch: ")
  (if (setq ss1 (ssget '((0 . "INSERT"))))
    (progn
      (setq cnt 0)
      (setq var_cmdecho (getvar 'cmdecho))
      (setvar 'cmdecho 0)
      (repeat (setq cnt (sslength ss1))
        (setq cnt  (1- cnt)
              blkn (cons (vla-get-effectivename (vlax-ename->vla-object (_dxf -1 (entget (ssname ss1 cnt))))) blkn)
        )
      )
      (setq blkn (_removedup blkn))
      (foreach x blkn
        (command "-bedit" x)
        (initcommandversion)
        (sssetfirst nil (ssget "_ALL"))
        (command "_.bhatch" "_P" "_S" "_LA" "." "_advanced" "_associativity" "_yes" "" "_select" "_last" "" "")
        (command "_.bsave")
        (command "_.bclose")
        (redraw)
      )
      (setvar 'cmdecho var_cmdecho)
    )
  )
  (princ)
)

;; removes duplicate element from the list
(defun _removedup (l)
  (if l
    (cons (car l) (_removedup (vl-remove (car l) (cdr l))))
  )
)

(c:test)

 

Posted (edited)
On 12/9/2022 at 7:15 PM, lido said:

Function undefined: _dxf, initcommandversion.

Rookie error, but:

 

With 

(command "_.bhatch" "_P" "_S" "_LA" "." "_advanced" "_associativity" "_yes" "" "_select" "_all" "" "")

;; or

 (vl-cmdf "_.bhatch" "_P" "_S" "_LA" "." "_advanced" "_associativity" "_yes" "" "_select" "_all" "" "")

 

it works when I open the same block and hatches successfully but with the code below and selecting the block it doesn't and gets stuck at the hatch dialog.

 

(vl-load-com)

; Tharwat 18th Sept 2013
; Modified on 2022.12.09 by 3dwannab to hatch circles and closed polylines entities in a block

; https://www.cadtutor.net/forum/topic/46782-deleting-hatch-from-blocks/?do=findComment&comment=396412

(defun c:BKHatchAll_Solid (/ ss1 blkn cnt var_cmdecho)

  (prompt "\nSelect blocks to hatch with solid hatch: ")
  (if (setq ss1 (ssget '((0 . "INSERT"))))
    (progn
      (setq cnt 0)
      (setq var_cmdecho (getvar 'cmdecho))
      (setvar 'cmdecho 0)
      (repeat (setq cnt (sslength ss1))
        (setq cnt  (1- cnt)
              blkn (cons (vla-get-effectivename (vlax-ename->vla-object (_dxf -1 (entget (ssname ss1 cnt))))) blkn)
        )
      )
      (setq blkn (_removedup blkn))
      (foreach x blkn
        (command "-bedit" x)
        (initcommandversion)
        (command "_.bhatch" "_P" "_S" "_LA" "." "_advanced" "_associativity" "_yes" "" "_select" "_all" "" "")
        (command "_.bsave")
        (command "_.bclose")
        (redraw)
      )
      (setvar 'cmdecho var_cmdecho)
    )
  )
  (princ)
)

;; removes duplicate element from the list
(defun _removedup (l)
  (if l
    (cons (car l) (_removedup (vl-remove (car l) (cdr l))))
  )
)

;;----------------------------------------------------------------------;;
;; _dxf
;; Finds the association pair, strips 1st element
;; args   - dxfcode elist
;; Example  - (_dxf -1 (entget (ssname (ssget) 0)))
;; Returns  - <Entity name: xxxxxxxxxxx>

(defun _dxf (code elist)
  (cdr (assoc code elist))
)

(c:BKHatchAll_Solid)

 

Edited by 3dwannab
Posted

Not had a chance to look at this but what happens if you comment out the (command "_.bhatch line? Does it finish the rest of the routine?

Posted
11 minutes ago, Steven P said:

Not had a chance to look at this but what happens if you comment out the (command "_.bhatch line? Does it finish the rest of the routine?

Yup. That hatch command is a strange one how it works on its own.

  • Like 1
Posted (edited)

@3dwannab Try replacing "BHATCH" with "-HATCH":

(command "_.-hatch" "_P" "_S" "_LA" "." "_advanced" "_associativity" "_yes" "" "_select" "_all" "" "")

Tested and works for me.

Edited by pkenewell
Posted

Perfect @pkenewell, thanks a lot.

 

Here's the working version. I don't know if I remember if there was a vla-get to get items that can be hatched. But for now this brute force method works.

 

(vl-load-com)

; Tharwat 18th Sept 2013
; Modified on 2022.12.12 by 3dwannab to hatch everything inside the block. Help over here: https://www.cadtutor.net/forum/topic/76450-hatch-objects-inside-a-block/

;; TO DO: Only hatch entities that can be hatched. Think there may be a vla-get for this. Not sure.

; https://www.cadtutor.net/forum/topic/46782-deleting-hatch-from-blocks/?do=findComment&comment=396412

(defun c:BKHatchAll_Solid (/ *error* acDoc blkn cnt ss1 var_cmdecho var_osmode)

  (defun *error* (errmsg)
    (and acDoc (vla-EndUndoMark acDoc))
    (and errmsg
         (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
         (princ (strcat "\n<< Error: " errmsg " >>\n"))
    )
    (setvar 'cmdecho var_cmdecho)
    (setvar 'osmode var_osmode)
  )

  (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))

  (setq var_cmdecho (getvar "cmdecho"))
  (setq var_osmode (getvar "osmode"))
  (setvar 'cmdecho 0)
  (setvar 'osmode 0)

  (prompt "\nSelect blocks to hatch with solid hatch: ")
  (if (setq ss1 (ssget '((0 . "INSERT"))))
    (progn
      (setq cnt 0)
      (repeat (setq cnt (sslength ss1))
        (setq cnt  (1- cnt)
              blkn (cons (vla-get-effectivename (vlax-ename->vla-object (_dxf -1 (entget (ssname ss1 cnt))))) blkn)
        )
      )
      (setq blkn (_removedup blkn))
      (foreach x blkn
        (command "-bedit" x)
        (command "_.-hatch" "_P" "_S" "_LA" "." "_advanced" "_associativity" "_yes" "" "_select" "_all" "" "")
        (command "_.bsave")
        (command "_.bclose")
        (redraw)
      )
      (setvar 'cmdecho var_cmdecho)
    )
  )
  (*error* nil)
  (princ)
)

;; removes duplicate element from the list
(defun _removedup (l)
  (if l
    (cons (car l) (_removedup (vl-remove (car l) (cdr l))))
  )
)

;;----------------------------------------------------------------------;;
;; _dxf
;; Finds the association pair, strips 1st element
;; args   - dxfcode elist
;; Example  - (_dxf -1 (entget (ssname (ssget) 0)))
;; Returns  - <Entity name: xxxxxxxxxxx>

(defun _dxf (code elist)
  (cdr (assoc code elist))
)

; (c:BKHatchAll_Solid)

 

  • Like 1

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