3dwannab Posted August 14, 2018 Posted August 14, 2018 Hi all, Here's a LISP that I'm having a problem with. Everything's working OK apart from getting the angle of the HATCH working. It doesn't work until I run it through a -hatchedit command. Is this a UCS problem? Drawing: Hatch Rotation Selection Issue.dwg LISP: (defun c:QSHLPASCB nil (c:QSHATCH_SAME_Layer_PatName_Rotation_PatScale_Color&BkgColor)) (defun c:QSHATCH_SAME_Layer_PatName_Rotation_PatScale_Color&BkgColor (/ bkgcol ent_1 laycolor layer nss patangle patname patscale ss_1 ssdata ) (while (not (and (setq ent_1 (car (entsel "\nSelect Hatch to get same Hatch entities as:\n\n- LAYER\n- PATTERN NAME\n- PATTERN ANGLE\n- PATTERN SCALE\n- COLOUR\n- BACKGROUND COLOUR\n-------------------------------------------------------------")) ssdata (if ent_1 (entget ent_1)) ) (= (cdr (assoc 0 ssdata)) "HATCH") (sssetfirst nil) (setq ss_1 (vlax-ename->vla-object ent_1)) (progn (setq bkgcol (vla-get-backgroundcolor ss_1) bkgcol (vla-get-ColorIndex (vla-get-BackgroundColor ss_1)) laycolor (vla-get-color ss_1) layer (vla-get-Layer ss_1) patname (vla-get-PatternName ss_1) patangle (vla-get-PatternAngle ss_1) patscale (vla-get-PatternScale ss_1) ss_1 (ssget "X" (vl-remove 'nil (list (cons 8 layer) '(0 . "HATCH") (cons 2 patname) (cons 52 patangle) (cons 62 laycolor) (cons 410 (getvar 'ctab)) (if (/= "SOLID" patname) (cons 41 patscale) ) ) ) ) nss (ssadd) ) (repeat (setq i (sslength ss_1)) (and (setq e (ssname ss_1 (setq i (1- i)))) (= bkgcol (vla-get-ColorIndex (vla-get-BackgroundColor (vlax-ename->vla-object e)))) (ssadd e nss) ) ) (princ (strcat "\n: ------------------------------\n <<< "(itoa (sslength ss_1)) (if (> (sslength ss_1) 1) " >>> similar HATCHES" " >>> similar HATCH") " selected.\n: ------------------------------\n")) (sssetfirst nil nss) ) ) ) ) (princ) ) Quote
Roy_043 Posted August 15, 2018 Posted August 15, 2018 The problem seems to be related to the negative (which is atypical) gc 52 value of the hatch in question. Copies of the hatch will have a positive gc 52 value. And probably _-HatchEdit also corrects the value. One way to solve this: Replace: (cons 52 patangle) With: '(-4 . "<OR") (cons 52 patangle) (cons 52 ((if (minusp patangle) + -) patangle pi pi)) '(-4 . "OR>") Quote
3dwannab Posted August 15, 2018 Author Posted August 15, 2018 Unfortunately, it still doesn't work. I've attached a new drawing showing a new issue also. I'm stumped as to why it's failing on both counts. Hatch Rotation Selection Issue dwg2.dwg Quote
Roy_043 Posted August 15, 2018 Posted August 15, 2018 This 2nd issue is clearly related to the 1st. Again the gc 52 value is atypical: 7.06858 (larger than 2pi). The only solution I see is to remove this part of the ssget filter and compare gc 52 values after applying such a function: ; Change an angle to fit in the range: 0 <= angle < 2pi. ; (KGA_Math_LimitAngleRange 8.3) => 2.01681 (defun KGA_Math_LimitAngleRange (ang) (rem (+ (rem ang (+ pi pi)) pi pi) (+ pi pi)) ) (equal (KGA_Math_LimitAngleRange ang1) (KGA_Math_LimitAngleRange ang2) 1e- Quote
3dwannab Posted August 15, 2018 Author Posted August 15, 2018 Thanks, It (does) work. But failing on some. I've replaced. (cons 52 patangle) With. (cons 52 (KGA_Math_LimitAngleRange patangle)) Maybe that's not that right way to use it? Quote
Roy_043 Posted August 16, 2018 Posted August 16, 2018 What I meant was: Create a selection set without filtering for the gc 52 value. And in the (repeat (setq i (sslength ss_1)) ...) loop also check gc 52 using the (equal) function with a fuzz. Quote
3dwannab Posted August 16, 2018 Author Posted August 16, 2018 What I meant was:Create a selection set without filtering for the gc 52 value. And in the (repeat (setq i (sslength ss_1)) ...) loop also check gc 52 using the (equal) function with a fuzz. I cannot get that to work as I think the issue is the angle of the hatch is not reading true. The problem hatch read 180 degrees in the properties. So I ran a script to get its props. The gc 52 value read -1.5708. I clicked on the hatch and typed in the properties dialog 180 degrees as it was. The gc 52 value now is 4.71239. I wonder how this translates. Quote
Roy_043 Posted August 17, 2018 Posted August 17, 2018 I don't know which hatch in which dwg you are referring to now. But it is worth checking the dwg's ANGBASE setting. Quote
3dwannab Posted August 17, 2018 Author Posted August 17, 2018 Any of the hatches that I'm having a problem with. I was trying to run the dialog of hatchedit and use a press key function by LeeMac to press my L to highlight the OK btn, then ENTER to close the UI and to fix the hatch patternangle as the (command "_.hatchedit" "" "" "" "") trick doesn't work but the UI method does. yip, ANGBASE is set to '0'. Quote
Roy_043 Posted August 17, 2018 Posted August 17, 2018 Maybe this helps: (defun KGA_Conv_Pickset_To_ObjectList (ss / i ret) (if ss (repeat (setq i (sslength ss)) (setq ret (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) ret)) ) ) ) (defun KGA_Math_LimitAngleRange (ang) (rem (+ (rem ang (+ pi pi)) pi pi) (+ pi pi)) ) ; (ResetHatchPatAngle (ssget '((0 . "HATCH")))) ; Argument: ss - Selection [pickset]. Selection should contain hatch objects. ; Return: Number of changed objects [int]. (defun ResetHatchPatAngle (ss / ang) (apply '+ (mapcar '(lambda (obj / ang) (if (and (vlax-property-available-p obj 'patternangle) (or (< (setq ang (vla-get-patternangle obj)) 0.0) (>= ang (+ pi pi)) ) ) (progn (vla-put-patternangle obj (KGA_Math_LimitAngleRange ang)) 1 ) 0 ) ) (KGA_Conv_Pickset_To_ObjectList ss) ) ) ) Quote
3dwannab Posted August 19, 2018 Author Posted August 19, 2018 (edited) Hi Roy, I got it working. I just set it to reset the picked HATCH. Still don't know how to translate those angles, but this seems like a good enough solution. ;;----------------------------------------------------------------------;; ;; Select HATCH by: Layer, Pattern Name, Pattern Angle, Pattern Scale, Colour & Background Colour ;; by 3dwannab, last modified on the 17.08.18 ;; Help from Roy_043 - http://www.cadtutor.net/forum/showthread.php?104909-HATCH-Angle-is-not-getting-selected-until-I-run-the-hatchedit-command&goto=newpost ;; FNs required: ;; - KGA_Math_LimitAngleRange ;; - KGA_Conv_Pickset_To_ObjectList ;; - ResetHatchPatAngle (defun c:QSHLPASCB nil (c:QSHATCH_SAME_Layer_PatName_PatScale_Color&BkgColor)) (defun c:QSHATCH_SAME_Layer_PatName_PatScale_Color&BkgColor (/ bkgcol ent_1 laycolor layer nss patangle patname patscale ss_1 ss_data ss_temp ) (while (not (and (setq ent_1 (car (entsel "\nSelect Hatch to get same Hatch entities as:\n\n- LAYER\n- PATTERN NAME\n- PATTERN ANGLE\n- PATTERN SCALE\n- COLOUR\n- BACKGROUND COLOUR\n-------------------------------------------------------------")) ss_data (if ent_1 (entget ent_1)) ) (= (cdr (assoc 0 ss_data)) "HATCH") (sssetfirst nil) (setq ss_1 (vlax-ename->vla-object ent_1)) (setq ss_temp (ssadd)) (progn (ssadd ent_1 ss_temp) (ResetHatchPatAngle ss_temp) (setq bkgcol (vla-get-backgroundcolor ss_1) bkgcol (vla-get-ColorIndex (vla-get-BackgroundColor ss_1)) laycolor (vla-get-color ss_1) layer (vla-get-Layer ss_1) patname (vla-get-PatternName ss_1) patscale (vla-get-PatternScale ss_1) patangle (vla-get-PatternAngle ss_1) ss_1 (ssget "X" (vl-remove 'nil (list (cons 8 layer) '(0 . "HATCH") (cons 2 patname) (if (/= "SOLID" patname) (cons 41 patscale) ) (if (/= "SOLID" patname) (cons 52 patangle) ) (cons 62 laycolor) (cons 410 (getvar 'ctab)) ) ) ) nss (ssadd) ) (repeat (setq i (sslength ss_1)) (and (setq e (ssname ss_1 (setq i (1- i)))) (= bkgcol (vla-get-ColorIndex (vla-get-BackgroundColor (vlax-ename->vla-object e)))) (ssadd e nss) ) ) (princ (strcat "\n\t\t<<< "(itoa (sslength ss_1)) (if (> (sslength ss_1) 1) " <<< similar HATCHES" " <<< similar HATCH") " selected\n: ------------------------------\n")) (sssetfirst nil nss) ) ) ) ) (princ) ) ;;----------------------------------------------------------------------;; ;; SUB-FUNCTIONS START ;;----------------------------------------------------------------------;; ; Change an angle to fit in the range: 0 <= angle < 2pi. ; (KGA_Math_LimitAngleRange 8.3) => 2.01681 (defun KGA_Math_LimitAngleRange (ang) (rem (+ (rem ang (+ pi pi)) pi pi) (+ pi pi)) ) (defun KGA_Conv_Pickset_To_ObjectList (ss / i ret) (if ss (repeat (setq i (sslength ss)) (setq ret (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) ret)) ) ) ) ; (ResetHatchPatAngle (ssget '((0 . "HATCH")))) ; Argument: ss - Selection [pickset]. Selection should contain hatch objects. ; Return: Number of changed objects [int]. (defun ResetHatchPatAngle ( ss / ang) (apply '+ (mapcar '(lambda (obj / ang) (if (and (vlax-property-available-p obj 'patternangle) (or (< (setq ang (vla-get-patternangle obj)) 0.0) (>= ang (+ pi pi)) ) ) (progn (vla-put-patternangle obj (KGA_Math_LimitAngleRange ang)) 1 ) 0 ) ) (KGA_Conv_Pickset_To_ObjectList ss) ) ) ) ;;----------------------------------------------------------------------;; ;; SUB-FUNCTIONS END ;;----------------------------------------------------------------------;; ;;----------------------------------------------------------------------;; ;; End of File ;; ;;----------------------------------------------------------------------;; Edited August 19, 2018 by 3dwannab Quote
Recommended Posts
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.