Source and Destination Arrows via VBA

Source and Destination Arrows via VBA

vince.krueger
Advocate Advocate
1,546 Views
9 Replies
Message 1 of 10

Source and Destination Arrows via VBA

vince.krueger
Advocate
Advocate

Good afternoon,

 

As I weed my way through the API calls I am finding most of what I am looking for so far.  One item that continues to elude me so far is how to programmatically (from an external application) add source and destination arrows to wires.

 

For example, I currently have my application doing the following:

  • Open Autocad Electrical
  • Create a new project
  • Add a drawing
  • Update the title block
  • Add 3Ø rails to the right and left half
  • Assign wire numbers to the left set

Now I want to attach the sets of rails, but can not figure out how.

 

Thanks in advance for the help

Vince

0 Likes
Accepted solutions (1)
1,547 Views
9 Replies
Replies (9)
Message 2 of 10

TRLitsey
Advisor
Advisor

Hi there,

 

Do every thing just as you have described.  It works best if you have wire numbers on the wires before adding the source arrow.  Select source arrow from ribbon.  This part is important.  Plan ahead and make sure you have a good scheme for creating the source codes.  The source code has to be unique for each source arrow.  Any source arrow can have multiple destination arrows but only one source arrow per unique source code.  The description can be anything you want.

 

Thank you

 

Please mark as solution if this works for you, kudos are always welcome.

 

Screenshot - 5_2_2016 , 2_33_56 PM.png

Screenshot - 5_2_2016 , 2_34_45 PM.png

Please mark as a solution if this works for you, kudos are always welcome
0 Likes
Message 3 of 10

TRLitsey
Advisor
Advisor

I reread your message.  Sorry I did not catch the VBA in your title.  Didn't mean to waste your time.

 

Thank you

Please mark as a solution if this works for you, kudos are always welcome
0 Likes
Message 4 of 10

vince.krueger
Advocate
Advocate

Not a problem, easy mistake.

 

I hope someone has an answer, this one is elusive.

 

Thanks,

Vince

0 Likes
Message 5 of 10

revans1234
Enthusiast
Enthusiast

I know this is a very old post, but did you solve it?

 

I'm looking into this, the route I am following to insert the source arrow (dest would be similar) is-

-find the insertion point (in my case, any open wire end in the circuit- I can always delete if I don't need it)

-insert a block (block to insert depends on wire end direction so need to find that- 4 options)

-alter the attributes of the inserted block for DESC1 as the description and SIGCODE for the internal wire code.

-update the wirenumber to take that of the wire segment it is on

 

Regards,

Roger.

0 Likes
Message 6 of 10

rhesusminus
Mentor
Mentor
Have you had a look at the API help for AutoCAD Electrical?
You should be able to do most of this with some lisp-code and "sendcommand".

Trond Hasse Lie
EPLAN Expert and ex-AutoCAD Electrical user.
Autodesk Expert Elite Alumni
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
0 Likes
Message 7 of 10

revans1234
Enthusiast
Enthusiast

Hello there Trond, it's been a while.

 

Good point you have made, as always.

 

Having been at this problem all day I have a workable solution for the circuits I have, based on the method above.

 

One interesting point is that there is no need to insert a block and update its wire number (WIRENO attribute). If I insert these arrows before I do the main wirenumber run (which is always the case) the aource arrows are updated.

 

The code finds wire ends by getting all the line entities on the drawing. It selects those on wire layers by a hack (searches for mm^2 in the layer name) and uses an array with the start and end  points and a flag so show if a point is repeated (so it is not an end).

 

The limitations are that it does not recognise a symbol at the wire end (except for an existing source arrow that is searches for at insertion time) so would add source arrows to every wire end even if something else was there. To make it water tight I would need to search for wire connection points on all the symbols in the drawing.

 

THis also means it does not recognise wire-srossing humps (which I could search for as an arc, I guess).

 

But om my current drawings all the connection points I need to auto-source (and there are hundreds), are above y =245 on the sheet. So it is easy to filter out the problems menioned above.

 

So I am good to go, but I do need to thank you for some attirbute hunting code you posted quite some time ago (for the PLC symbol break problem). That code is the basis for a some of this that searches for existing source arrows and check the name is not duplicated.

 

All the best,

 

Roger.

 

 

0 Likes
Message 8 of 10

rhesusminus
Mentor
Mentor
Glad to help Roger.
Feel free to show us a recording of your software in action when it's done!

And yes.. Automating like this takes a lot of thinking. So many variables needed to make it idiot proof. And yes... There will be idiots running the software 🙂


Trond Hasse Lie
EPLAN Expert and ex-AutoCAD Electrical user.
Autodesk Expert Elite Alumni
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
Message 9 of 10

vince.krueger
Advocate
Advocate
Accepted solution

Good morning Roger,

Sorry, I should have posted my solution.  Since then I have changed employers and never went back to clean things up.

I my application I am tracking each wire end so I already know where they are.  For me the solution turned out to be pretty easy.

- identify source location end and direction (all my source arrows go down or to the right)

- insert the appropriate symbol (HA1S4 for down, HA1S1 for right) and give it a selection set name

- set the appropriate attributes (SIGCODE and DESC1)

 

The routine calls look like the following

    sArrow = "HA1S4"     ' pointing down
    If (iOrientation = 1) Then sArrow = "HA1S1"     ' pointing right
   
    If (AutoCADe_Symbol_Insert("S" & sSigCode, sArrow, rX, rY) < 0) Then Exit Function
    AutoCADe_Attribute_Set "S" & sSigCode, "SIGCODE", sSigCode
    AutoCADe_Attribute_Set "S" & sSigCode, "DESC1", sDesc

 

Where the AutoCADe_Symbol_Insert primarily does

 

        appAutoCADe.ActiveDocument.SendCommand ("(setq " & sName & " (c:wd_insym2 """ & sComponent & """ '(" & Format(rX) & " " & Format(rY) & ") nil nil))" & vbCr)

 

And the AutoCADe_Attribute_Set looks like

 

    appAutoCADe.ActiveDocument.SendCommand ("(c:wd_modattrval " & sSelectionSet & " """ & sAttribute & """ """ & sValue & """ 1)" & vbCr)

 

(plus all the normal error checking and other handling)

 

Since you have yours figured out already, maybe this will help someone else at some point.  The API help is a good reference, as long as you are able to think like the creators, and fill in the holes that are left in the documentation.

 

Vince

0 Likes
Message 10 of 10

vince.krueger
Advocate
Advocate

By the way, the destination arrows are similar.

 

    sArrow = "HA1D2"     ' pointing down
    If (iOrientation = 1) Then sArrow = "HA1D3"     ' pointing right
   
    If (AutoCADe_Symbol_Insert("D" & sSigCode, sArrow, rX, rY) < 0) Then Exit Function
    AutoCADe_Attribute_Set "D" & sSigCode, "SIGCODE", sSigCode
    AutoCADe_Attribute_Set "D" & sSigCode, "DESC1", sDesc

 

0 Likes