Jump to content

Error control with the Hatch command


Recommended Posts

Posted

Hello everyone, I have a routine that I use to find the weight of several pieces and I'm having problems with the function that I use to find the area.
In this function I use the command "Hatch", because I click inside the piece, a hatch is made and I can see the area I'm "weighing", having the option to confirm or try again. The pieces I work on are always blown up, and errors always happen when the routine tries to insert the hatch into pieces with open points or sometimes into pieces that have ellipses and splines.
The drawback is that I use this function for a list of parts, (usually around 50 pieces at a time), using mapcar, and when an error occurs, I lose all the data previously captured.
I would like your help to try to control these errors if possible.
Thank you in advance!

(defun pega_area (/ pt_peso ent_pc x_confirma ar_pc)

  (while (/= x_confirma "Sim")
    (while (not ar_pc)
      (setq ent_pc nil
	    ar_pc nil
      )
      (initget 1)
      (setq pt_peso (getpoint "Click inside the area!"))
      (command "-hatch" "p" "s" "a" "a" "n" "i" "y" "" pt_peso "")
      (if (= "HATCH" (cdr (assoc 0 (entget (entlast)))))
	(progn
	  (setq ent_pc (vlax-ename->vla-object (entlast)))
	  (if (vlax-property-available-p ent_pc "area")
	    (setq ar_pc (vla-get-area ent_pc))
	    (vla-delete ent_pc)
	  )
	)
      )
    )

    (initget "Sim Não")
    (setq x_confirma
	   (cond
	     ((getkword "\nConfirma? [Sim/Não]<Sim>: "))
	     ("Sim")
	   )
    )

    (if	(/= x_confirma "Sim")
      (progn
	(if ent_pc
	  (vla-delete ent_pc)
	)
	(setq ar_pc nil)
      )
    )
  )
  (vla-delete ent_pc)
  ar_pc
)

 

Posted

2 things come to mind.

 

If hatch causes a error message you need to trap that and work out what to do next, the If will find the prior hatch so add it twice. Error trapping not my best subject.

 

The other is to have a max area size if that is at all possible.

 

 

  • Thanks 1
Posted
1 hour ago, BIGAL said:

2 things come to mind.

 

If hatch causes a error message you need to trap that and work out what to do next, the If will find the prior hatch so add it twice. Error trapping not my best subject.

 

The other is to have a max area size if that is at all possible.

 

 

 

I had commented on open points, but I was wrong, I'm sorry, the hatch command alone already intercepts when there is an open point.
I don't know why, but in some parts, like the one I'm attaching, the error occurs, and the program sends the following message:
error: Automation Error. Invalid input
I analyzed it closely, and the error occurs in:

  (if (vlax-property-available-p ent_pc "area")
       (setq ar_pc (vla-get-area ent_pc))

It considers (vlax-property-available-p ent_pc "area") True, but sends me the error when I enter with
(setq ar_pc (vla-get-area ent_pc))

If this error didn't end the routine, ar_pc would still be nill and I would click on another piece in the next while loop and then hit it manually.

hatch_problem.dwg

Posted

Question is the Ent-pc variable a vla-object? If so - this looks like a job for 

(vl-catch-all-apply 'function list)

Your Example would be something like:

(setq res (vl-catch-all-apply 'vla-get-area (list ent_pc)))
(if (vl-catch-all-error-message res) (alert "Somthing went Wrong - Try again."))

 

  • Thanks 1
Posted
2 hours ago, pkenewell said:

Question is the Ent-pc variable a vla-object? If so - this looks like a job for 


(vl-catch-all-apply 'function list)

Your Example would be something like:


(setq res (vl-catch-all-apply 'vla-get-area (list ent_pc)))
(if (vl-catch-all-error-message res) (alert "Somthing went Wrong - Try again."))

 

 

Problem solved, thank you very much!
I made the following change to the if condition.

(if (= "HATCH" (cdr (assoc 0 (entget (entlast)))))
	(progn
	  (setq ent_pc (vlax-ename->vla-object (entlast)))
	  (if
	    (vl-catch-all-error-p
	      (setq ar_pc (vl-catch-all-apply 'vla-get-area  (list ent_pc ))))
	    (progn
	      (setq ar_pc nil)
	      (vla-delete ent_pc)
	      )
	    )
	  )
	)

 

Posted
45 minutes ago, Jéferson Gustavo said:

Problem solved, thank you very much!

Glad I could help. :)

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