New to AutoLISP – Help with Rotation for Arrow Sequence Tool

New to AutoLISP – Help with Rotation for Arrow Sequence Tool

nikolai_sant007
Explorer Explorer
411 Views
7 Replies
Message 1 of 8

New to AutoLISP – Help with Rotation for Arrow Sequence Tool

nikolai_sant007
Explorer
Explorer

Hey everyone,

I'm just getting started with AutoLISP and I’ve written my first script (with a lot of help from AI 😅). The goal is to create a sequence of arrows in AutoCAD. Each arrow is made up of a block reference and a piece of MText. The label on the MText includes a letter (like "P") followed by an incrementing number (e.g., P1, P2, P3…).

Right now, the script is mostly working:

  • It inserts the block

  • It adds the MText label

  • The numbering increments correctly

The problem is with rotation — the arrows aren’t aligning with the direction I’m pointing during placement. Instead, they seem to rotate in a direction as if following a tangent to a circle formed between the original block and the new insertion point, rather than facing directly toward that point.

I’m completely new to AutoLISP and scripting in general, so I'm not sure how to properly calculate or apply the rotation angle based on the direction input.

If anyone could point me in the right direction or offer some advice, I’d really appreciate it. I’ve included the code below for reference.

Thanks in advance! 🙏

 

edit - Attached a sample DWG with an arrow(minus the grip that the original has for turning it) and the command loaded.

 

edit - Attached a second DWG that has a better design provided by ВeekeeCZ while helping me find a solution in this post.

0 Likes
Accepted solutions (1)
412 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant

@nikolai_sant007 

 

Welcome to the community. Looks like you did a lot of work.

At first glance, I can see that you are not turning off the OSNAPS mode (OSMODE). Try to turn it off and run the code.

If it does not help, please post a sample DWG with all we need to be able to test the code.

 

Message 3 of 8

nikolai_sant007
Explorer
Explorer

Thanks for the warm welcome. I appreciate you taking the time to review the code.  I just checked that the snapping mode was not the issue by toggling it off from the drawing but it did not change the command's behaviour. Additionally I have added the .dwg file as you said. 

0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant

Well, bad arrow block design makes the programming more challenging. Can the design be changed to this?

I'm not sure about scale. Is the text (attribute) height of 34000 correct to insert the block at a scale of 1?

0 Likes
Message 5 of 8

nikolai_sant007
Explorer
Explorer

Yes that is a better design. I have attached it to the post for future reference.

0 Likes
Message 6 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Here's a quick example with the modified block I posted. Guess you can pick it up from here.

 

(defun c:ArrowSequence ( / bname aname rparam number prefix point rangle)


  (setq bname "TestArrow"
	aname "NO"
	rparam "Angle1")

  (setvar 'attreq 0)
  (setvar 'attdia 0)

  (if (and (setq number (cond ((getint "\nInitial number <1>: ")) (1)))
	   (setq prefix (cond ((getkword "\nPrefix <P>: ")) ("P")))
	   )
    (while (setq point (getpoint "\nPlacement : "))
      (setq rangle  (getangle point "Direction: "))

      (command "_.insert" bname "_r" 0 "_s" 1 "_non" point)
      (setpropertyvalue (entlast) aname (strcat prefix (itoa number)))
      (setpropertyvalue (entlast) (strcat "AcDbDynBlockProperty" rparam) rangle)

      (setq number (1+ number))
      ))
  (princ)
  )
Message 7 of 8

nikolai_sant007
Explorer
Explorer

Thank You. This is much simpler.

0 Likes
Message 8 of 8

ВeekeeCZ
Consultant
Consultant

Just a short warning, those sysvars should be reset to the state before the routines start... that's the common practice. Just not sure whether you're aware...

0 Likes