Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rotate Block by X-axis upon insert

19 REPLIES 19
SOLVED
Reply
Message 1 of 20
JCprog
1243 Views, 19 Replies

Rotate Block by X-axis upon insert

Hello Everyone Smiley Happy

 

I created a dynamic block (light pole) which have a stretch parameter for height adjustments. This can only be done with the pole laying down, so everytime the block is inserted it always needs to be 3d rotated. I found a routine that Lee Mac wrote which works really well. I just need it to include the "insert" part. Please help!

 

Here's the insert part:

-INSERT
"C:\\pole01.dwg"
s  r 

 Here's the lisp from Lee

(defun c:bx90r ( / a e i p q r s x )
(setq a (/ pi 2.0))
(if (setq s (ssget "_:L" '((0 . "INSERT"))))
(repeat (setq i (sslength s))
(setq e (ssname s (setq i (1- i)))
x (entget e)
p (trans (cdr (assoc 10 x)) e 0)
r (cdr (assoc 50 x))
q (trans (mapcar '+ (cdr (assoc 10 x)) (list (cos r) (sin r) 0.0)) e 0)
)
(vlax-invoke (vlax-ename->vla-object e) 'rotate3d p q a)
)
)
(princ)
)
(vl-load-com) (princ)

 

Thanks in advance! Smiley Happy

 

19 REPLIES 19
Message 2 of 20
vivifira
in reply to: JCprog

two things.... you can use (command ".-insert" "C:\\pole01.dwg") and this will allow you insert set insertion point, scale and rotation of your block. you can add this to the beginning of your code by simply adding this just below the defun function and adding (command pause) right after this. so it should look something like this

(defun c:bx90r ( / a e i p q r s x )
(command ".-insert" "C:\\pole01.dwg")
(command pause)
(setq a (/ pi 2.0))
(if (setq s (ssget "_:L" '((0 . "INSERT"))))
(repeat (setq i (sslength s))
(setq e (ssname s (setq i (1- i)))
x (entget e)
p (trans (cdr (assoc 10 x)) e 0)
r (cdr (assoc 50 x))
q (trans (mapcar '+ (cdr (assoc 10 x)) (list (cos r) (sin r) 0.0)) e 0)
)
(vlax-invoke (vlax-ename->vla-object e) 'rotate3d p q a)
)
)
(princ)
)
(vl-load-com) (princ)

I hope this helps. 🙂
Message 3 of 20
smaher12
in reply to: vivifira

Or.... 

 

(command ".-insert" "C:\\pole01.dwg" pause "")

 

Without scale and rotate try...

 

(command ".-insert" "C:\\pole01.dwg" pause "" "" "")

Message 4 of 20
JCprog
in reply to: vivifira

Hi vivifira,
Thanks for the reply. The code didn't work, I get this error:
Command: BX90R

Unit-scaling inserted database...ADS request rejected
Command: '_.zoom _e
Command: '_.zoom _e
Command: '_.zoom _e
Command: '_.zoom _e
Command: '_.zoom _e
Command: BX90R ADS request rejected
Message 5 of 20
vivifira
in reply to: JCprog

Try this instead (command ".-insert" "C:\\pole01.dwg" 1 0 "") and no (command pause). let me know the results.
Message 6 of 20
JCprog
in reply to: vivifira

still no go....I get Value must be nonzero.
Message 7 of 20
hmsilva
in reply to: JCprog

(command ".-insert" "C:\\pole01.dwg" pause 1 "" pause)

 

EDIT:

"I created a dynamic block (light pole) which have a stretch parameter for height adjustments. This can only be done with the pole laying down, so everytime the block is inserted it always needs to be 3d rotated"

 

Could you attach your block?

HTH
Henrique

EESignature

Message 8 of 20
JCprog
in reply to: hmsilva

This works in the exception of picking the inserterd block again. After picking the insertion point it should finish up with x rotation rather than picking the block again.

 

(defun c:bx90r ( / a e i p q r s x )
(command ".-insert" "C:\\pole01.dwg" pause 1 "" pause)
(setq a (/ pi 2.0))
(if (setq s (ssget "_:L" '((0 . "INSERT"))))
(repeat (setq i (sslength s))
(setq e (ssname s (setq i (1- i)))
x (entget e)
p (trans (cdr (assoc 10 x)) e 0)
r (cdr (assoc 50 x))
q (trans (mapcar '+ (cdr (assoc 10 x)) (list (cos r) (sin r) 0.0)) e 0)
)
(vlax-invoke (vlax-ename->vla-object e) 'rotate3d p q a)
)
)
(princ)
)
(vl-load-com) (princ)

 

Message 9 of 20
JCprog
in reply to: hmsilva

Attached Block:

Message 10 of 20
hmsilva
in reply to: JCprog

Hi JCprog,
if you type at the command line

Command: -INSERT

and finalizing the block insertion, press F2 and copy/paste here the prompts.

 

EDIT: try

(command "_.-insert" "C:\\pole01.dwg" pause "" pause)

Henrique

EESignature

Message 11 of 20
JCprog
in reply to: JCprog

Here's what I get:

Command: BX90R
.-insert Enter block name or [?] <pole01>: 
C:\\pole01.dwg
Units: Inches   Conversion: 0'-1.0000"
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>: 1 Enter Y 
scale factor <use X scale factor>:
Specify rotation angle <0>:

Command:
Select objects: 1 found

Select objects:

 

Message 12 of 20
JCprog
in reply to: hmsilva

this one returns "ADS request rejected"
Message 13 of 20
hmsilva
in reply to: JCprog

did you change the

(command "_.-insert" "C:\\pole01.dwg" pause 1 "" pause)
to
(command "_.-insert" "C:\\pole01.dwg" pause "" pause)

Henrique

EESignature

Message 14 of 20
JCprog
in reply to: hmsilva

This code is really close:

(defun c:bx90r ( / a e i p q r s x )
(command ".-insert" "C:\\pole01.dwg" pause 1 "" pause)
(setq a (/ pi 2.0))
(if (setq s (ssget "_:L" '((0 . "INSERT"))))
(repeat (setq i (sslength s))
(setq e (ssname s (setq i (1- i)))
x (entget e)
p (trans (cdr (assoc 10 x)) e 0)
r (cdr (assoc 50 x))
q (trans (mapcar '+ (cdr (assoc 10 x)) (list (cos r) (sin r) 0.0)) e 0)
)
(vlax-invoke (vlax-ename->vla-object e) 'rotate3d p q a)
)
)
(princ)
)
(vl-load-com) (princ)

 *It's just other users might pick the wrong block at the end of this routine.

Message 15 of 20
hmsilva
in reply to: JCprog

Change
(setq s (ssget "_:L" '((0 . "INSERT"))))
to
(setq s (ssget "_L" '((0 . "INSERT"))))

HTH
Henrique

EESignature

Message 16 of 20
JCprog
in reply to: hmsilva

Yep! that perfected the code Smiley Very Happy

Thanks again Henrique!!!!! and also thanks to all who chipped in!!!!!

Message 17 of 20
hmsilva
in reply to: JCprog

You're welcome, JCprog
Glad I could help

Henrique

EESignature

Message 18 of 20
vivifira
in reply to: hmsilva

NP.... Just gald I could chip in. 🙂

Message 19 of 20
smaher12
in reply to: JCprog

Glad to see it is working....

Message 20 of 20
paullimapa
in reply to: JCprog

(setq pt (getpoint"\nPick Insertion Point: "))

(setq sc (getreal"\nEnter Scale: "))

(setq rt (/ (* (getangle"\nEnter Rotation: ") 180.0) pi))

(command"_.Insert""C:\\pole01.dwg" pt sc rt)


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost