Author Topic: macros start at wrong point  (Read 847 times)

rccon

  • Full Member
  • ***
  • Posts: 125
macros start at wrong point
« on: March 09, 2018, 10:11:45 AM »
In dcad 2016 I use several macros that insert a new object at the cursor position or the position of a handle. Often when I use one of these it will insert the new object at a point far distant from where it should go. If I then close dcad and restart it, the macros will work properly. I would like to find a permanent fix for this problem. Can anyone help?

Rob S

  • Hero Member
  • *****
  • Posts: 4535
    • Construction Estimating Program for General Contractors
Re: macros start at wrong point
« Reply #1 on: March 09, 2018, 04:12:43 PM »
Post your sample macro in a "code" quote  (# sign above compose window) that way some of the macro experts here might be able to see what would be going wrong.

Hard to tell how you programmed it without seeing a sample.
User since Pro-design

rccon

  • Full Member
  • ***
  • Posts: 125
Re: macros start at wrong point
« Reply #2 on: March 10, 2018, 09:37:11 AM »
Code: [Select]
Here's one that reflects along the y axis, then resets the default to x axis  so I can have separate hotkeys for the two axes and reduce mousework. It works fine after a restart, but later starts putting the reflection way off in the boonies.

 [>SetStartPoint
{
  }
>SelectMirror
{
  <PointXYZ 0.000000000000000e+000,0.000000000000000e+000,0.000000000000000e+000
  <Axis 1
  <Type 1
  }

>SelectMirror
{
  <PointXYZ 0.000000000000000e+000,0.000000000000000e+000,0.000000000000000e+000
  <Axis 0
  <Type 1
  }

>Undo
{
  }

code]

Lar

  • Hero Member
  • *****
  • Posts: 2815
Re: macros start at wrong point
« Reply #3 on: March 10, 2018, 11:53:53 AM »
Get rid of the:
Code: [Select]
[>SetStartPoint
{
  }
and see if that works  (is the opening square bracket in the actual code? It shouldn't be.


Lar

rccon

  • Full Member
  • ***
  • Posts: 125
Re: macros start at wrong point
« Reply #4 on: March 12, 2018, 12:37:15 PM »
Lar,  I'll try that. It may take a while to know if it works, since the macros only start misbehaving after I've been working for a while. I made this macro and several others with the macro record tool, so the lines were generated automatically. Might I be doing something wrong when I record a macro?  The opening square bracket is not in the code, dunno where it came from.

Thanks, Richard

rccon

  • Full Member
  • ***
  • Posts: 125
Re: macros start at wrong point
« Reply #5 on: March 12, 2018, 12:43:29 PM »
I deleted the opening  SetStartPoint  and the curlies, but that didn't work. Now it puts the new object at the same place each time. I want it to go at the next point set

Lar

  • Hero Member
  • *****
  • Posts: 2815
Re: macros start at wrong point
« Reply #6 on: March 12, 2018, 02:51:52 PM »

The SetStartPoint is your macro's origin. All your PointXYZ's set their points using your StartPoint as 0,0,0. So once you start the macro and click somewhere, that becomes 0,0,0 for that running of the macro. All your macro does is reflect your selection along the Y axis then along the X axis then undoes the 2nd mirror (but now your mirror command is set at X axis, as you said).

Hmmmmmm, the only other thing that I can think of is that you are thinking dcad uses the sticky handle when mirroring but it actually uses the selection handle, ie, not the handle with the zero in it but the big blue dot that appears where ever you click when click-selecting something. Or, if you dragselect it puts big blue at the center of the selection rectangle, or if you 'select all'  big blue goes at the center of everything selected, or if 'select when created' is on then big blue goes to the default spot for the type of entity just created (eg, for a box it goes at the front-left, I think... for a circle it goes at the center point).

I can't remember what 'Type 1' for the mirror command means ('make a copy'?) ...it's best to put comments to explain things like that when seeking help for macros on the forum...


If this is the case and according to your code the selection is already made when you start the macro. So, before starting the macro make sure the big blue selection handle is where you need it to be. When you set a fresh set of handles big blue comes instead of handle-zero. Later on when you select this entity again and if you have 'sticky handles' on, handle-zero will be where big blue first was and big blue would now be in one of the locations I described above. Sticky handles only stick to single entities and single blocks, solids and groups. If you select more than one of these and you use the handles command they would not stick, they would only work while this stuff is selected (and if you 'select previous' to reselect this set of stuff after selecting something else). Each individual will retain their sticky handles.


Lar
« Last Edit: March 12, 2018, 03:15:46 PM by Lar »

rccon

  • Full Member
  • ***
  • Posts: 125
Re: macros start at wrong point
« Reply #7 on: March 12, 2018, 04:52:06 PM »
I think I just figured it out. I'm not using sticky handles. Often when I sometimes reset the origin of the coordinate system so I can read the absolute coordinates of a point and know what it means. To use this macro I first select an object, giving it one handle, then activate the macro. Next I click somewhere and that point becomes the handle of the reflected object if I haven't set the origin since starting dcad. But if I have set the origin the reflected objects apears at some other place, usually far distant and off screen. Other macros which create new objects behave in the same way.
However, figuring out what causes a problem is not quite the same as fixing the problem, and in that regard, I am at a loss. Here is a macro that does nothing but set points for a line. It creates a 2x4 in cross section with a point at the center. If I haven't set the origin since starting dcad, the first point I click after choosing the macro is a corner of the 2x4, but if the origin has been reset it appears in a different place. It seems like >SetStartPoint is not recognizing the change of origin.  Is there a way to overcome this?

>SetStartPoint
{
  }
>Line
{
  <Color 0,0,0
  <LineStyle 0,2.0000,0.0000
  <PointXYZ 0.000000000000000e+000,0.000000000000000e+000,0.000000000000000e+000
  <PointXYZ 0.000000000000000e+000,1.250000000000000e-001,0.000000000000000e+000
  <PointXYZ 2.916666666666714e-001,1.250000000000000e-001,0.000000000000000e+000
  <PointXYZ 2.916666666666714e-001,0.000000000000000e+000,0.000000000000000e+000
  <PointXYZ 0.000000000000000e+000,0.000000000000000e+000,0.000000000000000e+000
  <PointXYZ 2.916666666666714e-001,1.250000000000000e-001,0.000000000000000e+000
  <PointXYZ 1.458333333333357e-001,6.250000000000000e-002,0.000000000000000e+000
  <PointXYZ 2.916666666666714e-001,0.000000000000000e+000,0.000000000000000e+000
  <PointXYZ 0.000000000000000e+000,1.250000000000000e-001,0.000000000000000e+000
  }

]

Lar

  • Hero Member
  • *****
  • Posts: 2815
Re: macros start at wrong point
« Reply #8 on: March 12, 2018, 09:46:05 PM »

It seems like >SetStartPoint is not recognizing the change of origin.  Is there a way to overcome this?
The purpose of >SetStartPoint is to ignore the origin of the drawing and become its own origin. When you start your macro and click that first point, that first point becomes the origin that the macro uses. Every >PointXYZ that the macro encounters is measured from that start point. The origin of the drawing is ignored. Far as I understand you can have as many setpoints in a macro as you want so each time you set one that becomes the origin that the macro uses until another setpoint is encountered. The origin of the drawing does not move but it is ignored while the macro runs.

To use this macro I first select an object, giving it one handle, then activate the macro. Next I click somewhere and that point becomes the handle of the reflected object I...

Once you start the macro the next click is the start point, not the mirror handle. The only reason the mirror sometimes work from there is because in the code the point is set at 0,0,0, which is the start point.


I think your problem stems from your misunderstanding of the start point. I myself only recently grasped that the start point becomes the origin that all >PointXYZ's are measured from. Whenever I recorded a macro the first thing I always did was delete the start point part if it was there. However, for my last recording I wanted to use start point so I left it in, not knowing that the pointxyz's would be measured from the start point. The macros was not working as expected so I had to go in and figure out why. Once I grasped the effect the start point was having I had to figure out another way to write the macro.


Lar
« Last Edit: March 12, 2018, 09:50:47 PM by Lar »

rccon

  • Full Member
  • ***
  • Posts: 125
Re: macros start at wrong point
« Reply #9 on: March 13, 2018, 09:25:56 AM »
Ok, I get that the next click after starting the macro is the start point, so 0,0,0, in the macro is that point. But why would it matter that I had earlier reset the origin by use of the "point,origin" command? Before I have done this, the macro works, setting the new object at 0,0,0 relative to that "next click". After I have reset the origin, the new object is set at a distant point.

Rob S

  • Hero Member
  • *****
  • Posts: 4535
    • Construction Estimating Program for General Contractors
Re: macros start at wrong point
« Reply #10 on: March 13, 2018, 10:26:07 AM »
I vaguely recall an issue posted some time back where the origin of the drawing is cached when it is loaded, and resetting it does not clear this cache, and some operations still find the original setting.

Can you confirm that after closing and reloading the drawing with the reset origin, and/or after closing and reloading Designcad, the operation of your macro works correctly again, until you change the origin again during the current session?

Also, if you offset the origin by a specific distance, does the mirror copy appear at twice that distance away?
User since Pro-design

rccon

  • Full Member
  • ***
  • Posts: 125
Re: macros start at wrong point
« Reply #11 on: March 13, 2018, 11:19:42 AM »
Rob, yes, the macro works correctly if the origin has not been set since opening dcad, i.e. it sets the new object at the first point clicked.  In response to your second question, I reset the origin one unit above the initial 0,0 of the session and now the macro sets the new object one unit above the first point clicked (not 2 units). Are we on the way to a solution?

Rob S

  • Hero Member
  • *****
  • Posts: 4535
    • Construction Estimating Program for General Contractors
Re: macros start at wrong point
« Reply #12 on: March 13, 2018, 11:50:10 AM »
I would say we are closer to understanding the issue!!!

Me only just another user with all kinds of ideas, me not know how to fix anything....

But helping those who know how to fix things in their efforts to understand the issue is a step along the way   :)
« Last Edit: March 13, 2018, 11:51:54 AM by Rob S »
User since Pro-design

Lar

  • Hero Member
  • *****
  • Posts: 2815
Re: macros start at wrong point
« Reply #13 on: March 13, 2018, 05:06:47 PM »

You will  have to describe in detail every step you take, or upload a video for us to grasp what is going on.


Eg, how are you setting the origin while the macro is running? I know this can be done with your macro but I would like to hear how you do it. Actually it's more like I would like to know if you do it during the running of the macro or do you do it between macros. Reason I would like to know this is because, like I said above, the start point is only in effect during the running of the macro. Once the macro ends the drawing's origin regains control. So, if you are changing the origin outside of the macro then it has nothing to do with the macro. Even if you are changing the origin during the macro you can only do it before you set the start point so it will still have no effect on the running of the macro.


When you say you set the origin 1 unit higher than previous, do you then run the macro? If you do, the start point will still be where ever you click next. Also, if the mirror then happens 1 unit higher all it means is it is using the drawing's origin. You must have changed the origin, then start the macro and used the regular PointXYZ command to set the start point, thus it would be 1 unit higher than before you set the origin. If you had snapped to an existing point to set the start point, or used the regular Point Relative from an existing point then the mirror would happen in the exact same place.


Another thing I would like to know is are you recording the macro each time you need it or are you reusing the same macro all the time?


Until I understand your process I am at a lost.


Lar

rccon

  • Full Member
  • ***
  • Posts: 125
Re: macros start at wrong point
« Reply #14 on: March 13, 2018, 07:00:12 PM »
I'll try to explain it more clearly. Starting with a new file, I drew a horizontal line and a vertical line, intersecting at point 0,0, the drawing origin, and saved it as macrotest.dcd. Then, using macro record, I made a macro that sets a bullet pointmark at the first point clicked after starting the macro, and saved it as "bullet.d3m". That produced the file attached below.

Then I took these steps:
1. start dcad
2. open macrotest
3.click the intersection of the lines to verify it's coordinates are (0,0). They are.
4.activate bullet.d3m.
5. click on a point of the horizontal line to the right of the intersection, producing one of the bullets in the attached screenshot. Just what the macro is supposed to do.
6. repeat #5, just to be sure it still works.
7.choose "point origin"
8. using "point relative", set the origin on the vertical line one unit above the intersection with the horizontal line.
9.activate bullet.d3m
10. click on the horizontal line to the left of the intersection. this produced a bullet point one unit above the horizontal line.
11. repeat, with the same result.

I have done this many times with the same result, with this and other macros that insert a new object. the origin is never changed while the macro is running. the macro inserts the object at the first point clicked after it is activated only if the origin has not been set since dcad was started, and if the origin has been set, the new object is inserted a distance away from the first point clicked equal to the distance from the opening origin to the new origin.

I think I attached a screenshot as clipboard01.jpg to this post, but don't see how to verify that. Can the picture be made to appear with the text? Anyway, I hope this is an adequate explanation of the problem.

>SetStartPoint
{
  }
>PointMark
{
  <Color 0,0,0
  <Layer 1
  <PointXYZ 0.000000000000000e+000,0.000000000000000e+000,0.000000000000000e+000
  <Size 1.000000000000000e-001
  <Type 5
  }