Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace block routine.Need help with rotation 1

Status
Not open for further replies.

vbcad

Technical User
Jul 12, 2002
159
0
0
US
I have a routine for replacing 4 of our blocks with 1 dynamic block. the routine works except i would like it to rotate the new block 180 degrees. This is not all my code as I have had some help from several sources. below is the code.
Code:
(defun c:RJBWD (/ ENT1 BL1 NWNM OLD ODNM)	;THIS PROGRAM REPLACES SELECTED J-box  BLOCKS WITH THE PROPER  BLOCK IN AN ELECTRICAL DRAWING
  (initerr3)
  (setq    ENT1
     (ssget "X"
       (list
         (cons 0 "INSERT")
         (cons
           2
           "JBWD"
         )
       )
     )
  )
  ;(IF (= ENT1 NIL) (C:SPO))
  (setq N (sslength ENT1))
  (setq I 0)
  (repeat N
    (setq BL1 (entget (ssname ENT1 I))
	  NM  (cdr (assoc 2 BL1))
    )
    (setq NWNM (cons 2 (strcat "Jbw")))
    (setq OLD (assoc 2 BL1))
    (entmod (subst NWNM OLD BL1))
    (setq I (1+ I))
  )
  ;(c:chvdq)
  (command "attsync" "N" "Jbw")
  (prin1)
  (reset3)
)
 
Add some lines to read current rotation, increase by 180:

(setq OLD (assoc 2 BL1));;existing data, add following lines
(setq Rot (cdr (assoc 50 OLD)));get current rotation
(setq NewRot (+ Rot pi));;add 180 degrees to rotation
(setq BL2 (subst NWNM OLD BL1))
(setq BL3 (subst (cons 50 NewRot)(assoc 50 BL2) BL2))
(entmod BL3)
(setq I (1+ I));;exist code to remain
 
thanks carlak

I pasted the code you have provided and it now errors. I have been looking for a long time and just can't find the problem. I get this in the text dialog.

Command: rjbwd
*Cancel*

Command:
Command:
Command:
Error: bad association list: (2 . "JBWD")
 
Not sure; by itself (2 . "JBWD") doesn't look bad..
Maybe you could temporarily change first line to :
(defun c:RJBWD ()
then run code, and test what the value of variables on the command line using the leading exclamation mark method, say
!NewRot
until you spot bad data-hopefully.

Post entire code, maybe we glitched...
 
I CHECKED THE VARIABLEs.
NWNM=Jbw
Ent1=204e ;selection set
old=JBWD
BL1=JBWD
B2=nil
B3=nil
ONE OF THE VARIABLES "odnm" IS NOT DEFINED IN THE CODE.
HERE IS THE COMPLETE CODE.
Code:
(defun c:RJBWD (/ ENT1 BL1 NWNM OLD ODNM)	;THIS PROGRAM REPLACES SELECTED DUPLEX RECEPTACLE BLOCKS WITH THE PROPER RECEPTACLE BLOCK IN AN ELECTRICAL DRAWING
  (initerr3)
  (setq    ENT1
     (ssget "X"
       (list
         (cons 0 "INSERT")
         (cons
           2
           "JBWD"
         )
       )
     )
  )
  ;(IF (= ENT1 NIL) (C:SPO))
  (setq N (sslength ENT1))
  (setq I 0)
  (repeat N
    (setq BL1 (entget (ssname ENT1 I))
	  NM  (cdr (assoc 2 BL1))
    )
    (setq NWNM (cons 2 (strcat "Jbw")))
    (setq OLD (assoc 2 BL1))
    (setq Rot (cdr (assoc 50 OLD)));get current rotation
    (setq NewRot (+ Rot pi));;add 180 degrees to rotation
    (setq BL2 (subst NWNM OLD BL1))
    (setq BL3 (subst (cons 50 NewRot)(assoc 50 BL2) BL2))
    (entmod BL3)
    (setq I (1+ I))
  )
  (prin1)
  (reset3)
  (command "attsync" "N" "Jbw")
)
 
NWNM should have been (2 . "jbw")
BL1 should have been a list of entity data
B1 & B2 would be nil, they are not used.
Are BL2 & BL3 also nil?

True ODNM not used but shouldn't cause a problem. Should be deleted.
Also the line "NM (cdr (assoc 2 BL1))" is not used, could be deleted.
 
Sorry I typoed. NWNM does equal (2. "jbw"). B2 and B3 are nil. BL1 is the entity data.
 
It's tough to troubleshoot this way :)

Are BL2 & BL3 also nil?
how about "NewRot"?
Are you sure you loaded the revised lisp?
 
NewRot shows nil as well. BL2 and BL3 are also nil. below is what I loaded. Would it help if i emailed the blocks?
Code:
(defun c:RJBWD (/ ENT1 BL1 NWNM OLD)	;THIS PROGRAM REPLACES SELECTED DUPLEX RECEPTACLE BLOCKS WITH THE PROPER RECEPTACLE BLOCK IN AN ELECTRICAL DRAWING
  (initerr3)
  (setq    ENT1
     (ssget "X"
       (list
         (cons 0 "INSERT")
         (cons
           2
           "JBWD"
         )
       )
     )
  )
  ;(IF (= ENT1 NIL) (C:SPO))
  (setq N (sslength ENT1))
  (setq I 0)
  (repeat N
    (setq BL1 (entget (ssname ENT1 I))
    )
    (setq NWNM (cons 2 (strcat "Jbw")))
    (setq Rot (cdr (assoc 50 OLD)));get current rotation
    (setq NewRot (+ Rot pi));;add 180 degrees to rotation
    (setq BL2 (subst NWNM OLD BL1))
    (setq BL3 (subst (cons 50 NewRot)(assoc 50 BL2) BL2))
    (entmod BL3)
    (setq I (1+ I))
  )
  (prin1)
  (reset3)
  (command "attsync" "N" "Jbw")
)
 
Yes it would help if you send me the blocks. Ver 2007 if possible. It's possible(probable) dynamic blocks handle rotation group codes differently than regular blocks, which may be the problem.
The routine also uses functions "initerr3" and "reset3", could you send those lisps also.

"c a b AT e e i t e a m DOT c o m" (w/o spaces)
 
Let me know if you get the message i sent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top