Author Topic: Sample macro "Entity ID" does not work  (Read 331 times)

Gymbo

  • Jr. Member
  • **
  • Posts: 77
Sample macro "Entity ID" does not work
« on: April 10, 2018, 02:48:31 PM »
Running the macro does nothing, this is it, dated 10/31/2012:

Code: [Select]
' This simple macro lets users select an item, then displays the
' Entity ID for that item.
'
' Prompt user to select an item
SetPOint "Please click on an object . . .", 1
' Get that XY Location where user elicked
  pointval jx jy jz 1
' Select whatever's at that point
>PointSelect
{
<Type 0
<pointxyz [jx, jy, jz]
}
' Get the Selected Item's ID
getselect 1, a
' Display that ID to the user
a$ = a
Message "Entity ID = ",a$
end


I'm using DC 2D, Version 23
« Last Edit: April 10, 2018, 02:51:25 PM by Gymbo »
Regards,

Jim

Lar

  • Hero Member
  • *****
  • Posts: 2790
Re: Sample macro "Entity ID" does not work
« Reply #1 on: April 10, 2018, 03:37:02 PM »

It worked for me, just as you wrote it.


The "a$=a" isn't necessary though, just use "a" in the message (without the quotes, of course).


Also, to select the entity you can just use >PointSelect without the <pointxyz (so the user has to set the point)... but I guess you used the setpoint to get the prompt. Personally it takes a while for me to notice the prompt in the status bar so I use a message.


Maybe put "precision 0" somewhere near the top so you don't get ".000" following the id number in the message.


Lar
« Last Edit: April 11, 2018, 05:05:18 AM by Lar »

Gymbo

  • Jr. Member
  • **
  • Posts: 77
Re: Sample macro "Entity ID" does not work
« Reply #2 on: April 10, 2018, 04:11:41 PM »

It worked for me, just as you wrote it.

Lar, I didn't write it, it came with DesignCAD 23 in the Sample Macros folder, I was just testing it, and it wouldn't even give me the prompt.
Regards,

Jim

Lar

  • Hero Member
  • *****
  • Posts: 2790
Re: Sample macro "Entity ID" does not work
« Reply #3 on: April 10, 2018, 08:18:08 PM »

Ok, my bad. That means it was written way back when. Maybe those unnecessary bits of code were necessary back then.


Still, it  did work for me. Wonder why it didn't for you?

bdeck

  • Hero Member
  • *****
  • Posts: 881
Re: Sample macro "Entity ID" does not work
« Reply #4 on: April 10, 2018, 09:55:41 PM »
Maybe the problem is the name. I'm guessing Lar did not give it the same name when he downloaded it, so he didn't have a problem with it..

Changed name to "entID,d3m" and it ran ok.  DC didnt like the space in the name. Perhaps it was looking for an executiable with a string argument.
« Last Edit: April 10, 2018, 11:31:04 PM by bdeck »

Lar

  • Hero Member
  • *****
  • Posts: 2790
Re: Sample macro "Entity ID" does not work
« Reply #5 on: April 11, 2018, 05:32:31 AM »

I didn't name it at all. When testing code I normally just copy from the post and paste at the top of an existing macro that I have open at the time, and put in a very noticeable "end" so it stops before it gets into my code. When done testing I remove the test code. I think my brain has generated over 100 billion unique file names over the years and I'm worried that my name generating facility may crash (just kidding, but since I copied I would have to name it myself).


I'll confess that I didn't read the entire date in the starting post so didn't notice the "12" at the end of it. I wonder if that code was originally written in 2012. Other than DT's macro contributions to the forum I don't think any new auxiliary dcad files were written since 1993 or so. Well, the original bsc macros would have been adapted to the new d3m format (anybody remembers what year that happened?) but I won't call them new (those contributed by the forum members were way more imaginative so further macro writing by the dcad staff were deemed unnecessary, I guess).


Lar

bdeck

  • Hero Member
  • *****
  • Posts: 881
Re: Sample macro "Entity ID" does not work
« Reply #6 on: April 11, 2018, 08:08:48 AM »
Perhaps it was looking for an executable with a string argument.

And a macro too.

As i turns out, when "Entity ID" is typed into the command liine (or selected from the command line dropdown), DC first looks for a DC command "Entity", if the command is not found, DC then looks for a macro with the name "Entity.d3m." If DC finds it, DC will run the macro "Entity.d3m" and pass the parameter "ID" to it. If "Entity.d3m" is not found, DC search for an executable with the name "Entity.exe." If no executable is found, DC will do nothing.

When "Entity ID.d3m" is selected from the menu/tools/MacroExecute/  file selector, DC will run the macro "Entity ID.d3m" without first searching for a DC command or executable.

This is true even if "Entity.d3m" and "Entity ID.d3m" are both in the same macro folder. All as it should be according to the SDK.

« Last Edit: April 11, 2018, 08:56:23 AM by bdeck »

Lar

  • Hero Member
  • *****
  • Posts: 2790
Re: Sample macro "Entity ID" does not work
« Reply #7 on: April 11, 2018, 08:36:53 AM »

If, in the command line, the full name is in quotes then dcad runs the correct macro. The quotes would remain long as dcad stays open. However, once you close and reopen dcad then the quotes are gone so you just have to replace them around the macro name in the drop down list. My macros names have all manner of legitimate non-alphanumeric characters so I always have to replace the quotes. Sometimes I remove the spaces from a macro name to avoid this but once I put it in a custom toolbox I usually don't mess with the name.


Lar

bdeck

  • Hero Member
  • *****
  • Posts: 881
Re: Sample macro "Entity ID" does not work
« Reply #8 on: April 11, 2018, 09:04:48 AM »
If, in the command line, the full name is in quotes then dcad runs the correct macro.

Lar, Good info.

When "Entity ID.d3m" is typed into the command line without quotes, DC runs "Entity.d3m" and passes the argument "ID.d3m".

When either or "Entity ID" or "Entity ID.d3m" is typed into the command line with quotes, DC runs "Entity ID.d3m."

Well, the original bsc macros would have been adapted to the new d3m format (anybody remembers what year that happened?)

The earliest d3m macros in my version 15 and 17 folders (the only ones I have installed as admin, thanks microsoft) show 1997 dates.  This particular macro has a date of 2001.
« Last Edit: April 11, 2018, 12:43:46 PM by bdeck »

Gymbo

  • Jr. Member
  • **
  • Posts: 77
Re: Sample macro "Entity ID" does not work
« Reply #9 on: April 11, 2018, 10:49:59 AM »
Yeah, it was the space in the name, I wonder when Windows decided to allow spaces, thanks, works now that I replaced the space with _.

I found a DVD with an old DC archive, the Basiccad folder has macros dated 1992, some are .bsc files, some are .d3m and some are .dcm. They all have the same date so none of them are mine.
Regards,

Jim