AutoCAD Electrical Forum
Welcome to Autodesk’s AutoCAD Electrical Forums. Share your knowledge, ask questions, and explore popular AutoCAD Electrical topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Invoke wd_insym2

18 REPLIES 18
Reply
Message 1 of 19
AdrianSaf
929 Views, 18 Replies

Invoke wd_insym2

Hello,

 

I have an issue with invoking wd_insym2 from c#.

When calling the method from command the user gets to select the insert point, clicks, the block is inserted and an entity name is returned.

Command: (c:wd_insym2 "HDS11FR" nil nil nil)
 WD_M insert: C:\users\public\documents\autodesk\acade 2014\libs\jic125\WD_M.dwg
Specify insertion point:
 Retrieving project-wide component tags in use...
 reading project database file . . .
<Entity name: 7ffffb13bf0>

 

When calling the command from c# using Application.Invoke method like bellow:

resBuf = new ResultBuffer();
            resBuf.Add(new TypedValue((int)LispDataType.Text, /*MSG0*/"c:wd_insym2")); //function to call
            resBuf.Add(new TypedValue((int)LispDataType.Text, componentToAdd)); // block name                
            resBuf.Add(new TypedValue((int)LispDataType.Nil)); //insert point 
            resBuf.Add(new TypedValue((int)LispDataType.Nil)); // scale
            resBuf.Add(new TypedValue((int)LispDataType.Nil)); // options                
            res = Application.Invoke(resBuf);

 

The command does not seem to end.The following happens:

1. User is prompted for insertion point for the block

2. User clicks

3. Component is added to the drawing

4. Command does not end; (seems to still be waiting for input)

 

 

Any reason why it is doing that? Am I doing something wrong from c#? Is there a way to workaround the problem (If I'm not doing something wrong)?

 

Thank you,

Adrian Safta

18 REPLIES 18
Message 2 of 19
PatMurnen_Adsk
in reply to: AdrianSaf

Adrian Safta,

 

I have no expertise in c# so I passed your question along to a coworker. Here is what they said to try -

 

string cmdStr = "(c:wd_insym2) ";

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

doc.SendStringToExecute(cmdStr, truefalsefalse);

 

They didn't try it and looking at it I wonder if there is a missing argument. But, maybe this points you in the right direction.

 

Regards,

Pat



Pat Murnen
Principal Content Developer
Product Development – AutoCAD Product Line Group

Autodesk, Inc.

Message 3 of 19
WoHo
in reply to: AdrianSaf

Have the same behaviour. But it is possible to proceed with any other command. Maybe you send a cancel-command to the command line?

 

PS: There are different methods to invoke a Lisp command, I have always the same result ...

 

Other ACADE API commands work as expected.

 

WH

Message 4 of 19
AdrianSaf
in reply to: PatMurnen_Adsk

Hello Pat,

 

Thank you for your answer.

 

SendStringToExecute has a different funtionality than invoke:

 

1. Invoke will call the Lisp method and wait for it to return (SendStringToExecute does not do that)

2. Invoke will return the entity name from the Lisp call (SendStringToExecute obviouselly does not do that as it does not wait for the method to finish) - I could do a editor select last if I could somehow wait for the user input to end.

 

I need to be able to call the method, wait for the user input and then get the added block reference id. Is this the correct forum to ask this on? I am able to invoke other lisp methods so it seems to be related to this electrical lisp method. That is why I asked here.

 

Thank you.

 

 

Message 5 of 19
AdrianSaf
in reply to: WoHo

Hello WoHo,

 

Thank you for your answer.

I'm not sure I understand how I would be able to send a cancel during an invoke call (it's a sync call so I'll only have control back in c# after the lisp method ends - and it does not end).

 

Thank you.

Message 6 of 19
vladop
in reply to: WoHo

Since you are discussing about C#, I have a question:

Is it possible to call ACAD Electrical API functions in closed drawings using ObjectDBX?

 

Vladimir

 

 

Message 7 of 19
AdrianSaf
in reply to: PatMurnen_Adsk

Enabled lisp debug and it seems to stop in wd_sym_ins_elect_blk_pause waiting for other input after the block is added (mouse button clicked)

 

 

IN:wd_sym_prelims
IN:wd_1_get_gridrefs
OUT:wd_1_get_gridrefs
OUT:wd_sym_prelims
Specify insertion point:
IN:wd_sym_ins_elect_blk_pause =HDS11FR

 

Message 8 of 19
WoHo
in reply to: vladop

Hello Vladimir,

 

can I assume that you have an own RealDWG application? I believe that it will not be possible to use the AutoCAD Electrical API in an own RealDWG application (a 'closed' drawing); all the AutoCAD Electrical files (arx, dll, lsp, etc.) must be loaded, that the API works. Moreover, some API commands need an open AutoCAD Electrical drawing, even without user interaction, the command 'executes' on the current drawing.

 

One remark: AutoCAD Electrical accepts drawings created 'outside' of it; all objects must be of course on the correct layer, have the correct attributes, etc.

 

WoHo

Message 9 of 19
WoHo
in reply to: AdrianSaf

Hello AdrianSaf,

 

I was wrong, it is not possible to send a cancel-command - because of the pause you also discovered enabling the debug mode; however it is possible to proceed with any other (or the same) command; only the 'visual' effect at the command line gives the impression that AutoCAD Electrical is still in the API routine.

 

WoHo

Message 10 of 19
vladop
in reply to: WoHo

No, I don't have my own RealDWG application.

Actually I use ACAD Electrical API in Visual LISP. On the Nate Holt's blog I found functions like wd_dbx_ssget and wd_dbx_entattr that allow me to modify closed drawings. It's much faster. But, as far as I know, it is not possible in Visual LISP to call ACAD Electrical API functions in closed drawings.

Since I plan to learn C# or C++, I wonder if it is possible to call API in closed drawing using ObjectDBX. I don't expect that it is possible, but it's better to ask.

 

Vladimir

Message 11 of 19
wenqi.liang
in reply to: vladop

Hello Vladimir,

 

My name is Wenqi a developer from AutoCAD Electrical team.

 

While I am trying to put the code you mentioned into debug, I realized that you may be looking for something slightly different reading your last reply. So I would like to understand whether you would like to get c:wd_insym2 working on closed drawings through C# calls? If that is the case, I am afraid that the answer is negative. This is mainly due to the fact the API requires additional input of the insertion location by asking user to click on the drawing, which cannot happen if a drawing is closed. Of course, it is possible to programatically open the drawing, but that is not the way c:wd_insym2 behaves.

 

Having said that, what you mentioned about the API unable to return when triggered through Invoke is not expected. I am seeing slightly different behavior on my end when I am debugging the issue. The behavior is not what I would expect either. Anyway, I will give an update once I have any findings.



Wenqi Liang
Software Engineering Manager

Message 12 of 19
vladop
in reply to: wenqi.liang

Thanks for your repay.

My question is general about calling any ACAD Electrical API function using ObjectDBX.

As I sad I use Visual LISP, so I hope that my question about ObjectDBX is clear, because I only read about ObjectDBX and I haven't used it yet.

 

Regards,

Vladimir

 

Message 13 of 19
wenqi.liang
in reply to: vladop

Hi Vladimir,

 

Thanks for the reply.

 

If I understand correctly, the question is about whether we can make Electrical LISP API to work on closed drawing files by calling them through C# or C++. The quick answer is unfortunately no.

 

Majority of the Electrical LISP API make changes to drawing files. These APIs assume that they are making changes to the current drawing opened by AutoCAD. If we want these API to work on closed drawing, it is necessary to at least tell these APIs which drawing they should modify probably by providing them with the path to drawing file. Besides some API needs user interaction, e.g. pick an insertion point, which requires the drawing to be open and active.

 

Having said all that, there is actually an alternative. There are ways to open a drawing file through C# and C++. Once drawings are open, it is possible to run the LISP APIs subsequently. But if the requirement on "closed drawing" is a must, this is no longer a feasible alternative.

 

Hope that helps to clarify the query.



Wenqi Liang
Software Engineering Manager

Message 14 of 19
vladop
in reply to: wenqi.liang

It helps a lot, thank you once again.

 

Vladimir

Message 15 of 19
AdrianSaf
in reply to: wenqi.liang

Hello Wenqi,

 

My question was not related with working on a closed drawing. I'm trying to run the command (c:wd_insym2) from c# code on an opened drawing in the editor and expectiog user input.

As I understand it this seems to be a bug in the electrical API (that the command stops at the stage of getting input from the user). Could you please confrim that?

 

Also Vladimir, I don't think it was a good ideea to post your question on this thread (things got a bit mixed up because of that - separate thread would have been better I think).

 

Thank you,

Adrian.

Message 16 of 19
wenqi.liang
in reply to: AdrianSaf

Hi Adrian,

 

Thanks for checking on this. I understand the question started the thread (My apologies if my discussion with Vladimir has led to any confusion on this). I was not able to reproduce the same behavior as stated unfortunately. Would you mind to share how the call to the Invoke has been setup? I am kind of assuming the Invoke call to c:wd_insym2 is executed either in a customized AutoCAD command written in C# or in a LISP API written in C#. That information is going to be really helpful in diagnosing the issue here.

 

Once again, thank you for sending in the problem report and we really appreciate the feedback that can help to shape our product even better!



Wenqi Liang
Software Engineering Manager

Message 17 of 19
AdrianSaf
in reply to: wenqi.liang

Hello Wenqi,

 

Thank you for taking the time to look at this issue. 

Below is the exact C# code that I'm using. You are correct in assuming I'm calling the lisp method from a C# custom command. (If I've not mentioned this before - I'm using AutoCAD Electrical 2014)

 

[CommandMethod("ACPOC", "POCEComp", "POCECompLocal", CommandFlags.Modal)]
        public void InsertElectricalBlockCommand()
        {
            ObjectId blockId = ObjectId.Null;
            using (ResultBuffer resBuf = new ResultBuffer())
            {
                resBuf.Add(new TypedValue((int)LispDataType.Text, "c:wd_insym2")); //Lisp function to call
                resBuf.Add(new TypedValue((int)LispDataType.Text, "HDS11FR")); // block name                
                resBuf.Add(new TypedValue((int)LispDataType.Nil)); //insert point 
                resBuf.Add(new TypedValue((int)LispDataType.Nil)); // scale
                resBuf.Add(new TypedValue((int)LispDataType.Nil)); // options
                using (ResultBuffer res = Application.Invoke(resBuf))
                {
                    if (res != null)
                    {
                        foreach (TypedValue val in res)
                        {
                            if (val.TypeCode == (int)LispDataType.ObjectId)
                            {
                                blockId = (ObjectId)val.Value;
                            }
                        }
                    }
                }
            } 

 

Thank you,

Adrian 

 

Message 18 of 19
AdrianSaf
in reply to: AdrianSaf

One way I've found to go around this was like this:

1. Insert the block using c:wd_insym2 and a fixed point - say the origin (this will give the blockreference id)

2. Have an entity jig and jig the blockreference (with attributes) so the user can select where to insert it

Message 19 of 19
wenqi.liang
in reply to: AdrianSaf

Hi Adrian,

 

Good to know that there is at least a work around that could help a bit on your side. And hopefully unblock your work from progressing.

 

I have checked the code you provided and was able to confirm the problem. The cause of the issue still puzzles me though, and I don't have a better workaround to suggest at the moment. Let me check in with some folks to see if we can dig out some details on why this happens.



Wenqi Liang
Software Engineering Manager

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

Post to forums  

Autodesk Design & Make Report

”Boost