Change point location - vba

I want, when a point is selected, the co ordinate values of the point to display in a userform:
Values of x, y & z should be displayed in the textboxes.
Some points are in "ONCURVE" or "ONSURFACE" type. Those points won't show x, y & z values.
Image for reference
First point is co-ordinate defined, second point is ONCurve defined and the third is ONSURFACE defined.
How do I extract x y z co-ordinate values for those points?
I also need to change the point location by changing the values from the textbox.

As GisMofx said, you should use the base Point class and you can use the methods GetCoordinates
Take a look in the API documentation - you should be able to find some examples and if not try to come up with something
CATIA API Point Description

Related

CATIA VBA: Extract name of generated point in CATDrawing

I'm tearing my hair out trying to work with generatedpoints in draft view. I have a 3D model with points that are named in a particular way, per the picture below:
point names
Then on the CATDrawing, I have generated views that show those points. if I click those points in 2D, they are named in the following manner, "GeneratedPoint (insert 3D point name here)". You can see this naming example below:
2D generated naming
Now, what I'm trying to do in VBA is run a code that will select those generated points in a view, duplicate geometry on them, and name that duplicated geometry to match the 3D point names. My problem is, I can't seem to access the "GeneratedPoint" names that show up when I click the points in 2D. Below is a snippet of my code where I'm trying to access the name of the selected points:
For j = 1 To totalcnt
Set bSel = aDoc.Selection
bSel.Add ActiveView
bSel.Search "Name='*GeneratedPoint *',sel"
Set nm = bSel.Item(j)
desc = nm.Name
desc = nm.Value.Name
Usually when I have a selection, and I make an object from one of those selections, I can access the name through selection.Item(j).Name or selection.Item(j).Value.Name, but in this case neither one works.
at the desc=nm.Name line above, it gives me a name of "CATIASelectedElement16", not the actual name I see in the status bar when I click it in the drawing. And when I use desc=nm.Value.Name it gives me "Front View", which is the name of the view these points are in. I know it's selecting the points correctly, I can see them get selected, and I can see the count on the selection object matches my number of points. What am I missing? For reference, when I run the line Set nm=bSel.Item(i), that object looks like this in the Locals window.
Object in Locals window
As you can see in that picture, the object Type is DrawingView, whereas I would expect it to be a point. Does anyone have any ideas on how to access the name of a generated item in 2D? So far the only way I can interact with it at all is by using selection.Search, which will find them by name, but I have no way of then actually using the specific names of those points it found. Any insight would be appreciated!

In visual basic, is it possible to teleport my cursor to x*y coordinates (Not x,y)

So I have this program in visual basic that requires teleporting your cursor around and clicking. Kinda like an automatic cheat for a game but not really a cheat.
Anyways I want the user to set coordinates to a point, then set those coordinates to a value, then with the push of a button teleport to those coordinates.
Alright I can make him get the coordinates. I can make the cursor teleport. I can set the coordinates he got to an integer X and an integer Y so the cursor teleports there. But I have to do all that 8 times. So I need 24 integers.
I was thinking, maybe I can skip all that if I can multiply xy so lets say he sets the coordinates to 320 (x) and 72 (y). (320,72) Alright so If I multiply xy I get the pixel number on the screen that exists in that coordinate (right?)
Alright that makes it so we only have 8 integers which is much less.
But how do I make the cursor teleport to the location "X*Y" (in the case of 320*72 it is pixel number 23040).
*TL;DR is it possible to convert this Windows.Forms.Cursor.Position = New Point(320,72) into this Windows.Forms.Cursor.Position = New Point(23040 (which is 320*72))*
Is it possible?
I can't think of a way of doing it please help me. Thanks.
No. (x, y) is not equivalent to (x * y).
The reason why is obvious if you give it some thought. There are many different input values for x and y that would give the same product. For example, 6 * 1 = 6, and so does 2 * 3. Which location on the screen would 6 correspond to? The point at coordinates (6, 1), (1, 6), (2, 3), or (3, 2)?
There might be a better way of doing this, but I find the description in your question to be very difficult to understand. If all you want to do is simulate a click event at a particular location on the screen, you do not need to explicitly move the cursor there first. I'd suggest how to do that, but it is not clear what language you're using. You've tagged the question [vbscript], but then talked about Windows Forms, which doesn't exist in VBScript. If you are using VB.NET, you will probably end up P/Invoking the SendInput function. Google for code examples.
While I agree with other answers/comments, what you describe is possible, but you cannot simply multiply the x and y coordinates. You need to take the screen width into consideration:
Private Function PointToPixelNumber(pt As Point) As Integer
Return pt.Y * Screen.PrimaryScreen.Bounds.Width + pt.X
End Function
Private Function PixelNumberToPoint(pixelNumber As Integer) As Point
Return New Point(pixelNumber \ Screen.PrimaryScreen.Bounds.Width, pixelNumber Mod Screen.PrimaryScreen.Bounds.Width)
End Function
Please note that this code uses integer division (\). It also assumes that the origin is at the upper left of the screen and is zero based (i. e. the upper left coordinate is (0, 0))

Can't use all arguments with Shapes to control line in the GraphicsWindow

After trying a few things inside small basic to make a line follow the mouse but not move the entire line, I recently came across a problem. Originally I was trying to constantly have a line update so as it stays connected from one point to the mouse position by clearing the graphics window and redrawing a line from the bottom right to the mouse. This could not work and was to resource intensive. However, now I have come across Shape.addline and shape.move. But I'm not too sure as to how they work, from my understanding, a shape can have it's own name by doing:
[Shapename] = Shapes.addline(positions)
and then that shape can be moved using:
Shapes.move(Shapename,Coordinates)
In my case it's:
L1 = Shapes.AddLine(0,GraphicsWindow.Height,GraphicsWindow.MouseX,GraphicsWindow.MouseY)
(Drawing a line from the bottom left corner to the mouses position)
and
Shapes.Move(L1,GraphicsWindow.MouseX,GraphicsWindow.MouseY)
The only problem is that Shapes.Move only supports 3 arguments being:
shapeName
X
Y
But, when drawing the line (Shapes.AddLine), I use 4 arguments:
X1
Y1
X2
Y2
This means I can only control those two positions. So, how would you control the other two? If we can only modify X1 and Y1, is there any way of still using at least something similar to the shape.move method but be able to control the other X2 and Y2 positions? Primarily, I would like to actually Only change the X2 and Y2 positions, as I'm trying to make a line originate from one point and stay there, then alter the opposing point so that it follows the mouse, and not move the entire shape. If none of this is possible, is there any known way of moving / changing only the X2 and Y2 coordinates of a line without having to clear the entire screen?
Ah yes. These are the shortcomings of small basic. Shapes.move will not let you define a starting and ending point of a line. What you will need to do is move the center of the line in between the first point and the cursor, and the rotate it correctly. Like so:
Mouseline = Shapes.AddLine(0,0,100,0)
Shapes.Move(Mouseline,200,200)
GraphicsWindow.MouseMove = OnMouseMove
Sub OnMouseMove
XDif = (GraphicsWindow.MouseX-250)
YDif = (GraphicsWindow.MouseY-200)
If XDif <> 0 Then
MouseAngle = Math.ArcTan(YDif/XDif)
EndIf
If XDif < 0 Then
MouseAngle = MouseAngle + 3.14 '180 degrees in radians
EndIf
Shapes.Rotate(Mouseline,Math.GetDegrees(MouseAngle))
Shapes.Move(Mouseline,(Math.Cos(MouseAngle)*50)+200,(Math.Sin(MouseAngle)*50)+200)
EndSub
Another way of doing this is with the LitDev extension (http://litdev.co.uk/). It has a MoveLine(x1,y1,x2,y2) function in it.
im guessing u would alter the end of the program where it says math.cos(mouseangle) change the 200 to 0 and change the other 200 to the bottom. so if what im trying to figure out, ur trying to get the line to only project in the 1st quadrant in a cortesian plane yes?

Is it posible to get the position of point on an excel graph axis

I'm not sure this is possible but thought this was the best place to ask.
Is it posible to get the position of a series value on a graph in excel?
For example, if I have a line graph in excel that has time along the x axis, is it possible to (using VBA) get the position of a specific point on that axis.
What I am trying to do is have a vertical line that is can be positioned based on a date entered by the user.
like this
Where the green line could be positioned by entering in a date (rather than just being manually moved) (or also it could be set to automatically move to the current date etc).
I was then thinking that if the position is on the graph is queryable, then I can just access the line object and move it to any position I wanted through VBA.
Any Ideas? or is this just not possible?
The "cleanest" way to do this is to add the line to the chart as a new series. In that way, Excel handles all of the positioning and your work is simplified. To get a vertical line on a chart, there are a number of options. I prefer this route:
Create a small 2x2 area with two dates and two values
Add in the date or x-axis value you want the line at (E3 in image). You can use =TODAY() here or some manually entered value.
Set the second x-axis value equal to the first
Use MAX and MIN on the data to get the values for each date. You can also use 0 and 1 and a secondary axis, but I think MAX/MIN is easier.
Add the data to the chart and format as a marker with straight line.
Formulas
E3: =TODAY()
E4: =E3
F3: =MIN(C3:C27)
F4: =MAX(C3:C27)
Result and chart data series for vertical line

How do I avoid the first(and last) column of a x-capped chart being truncated?

I've been fiddling with a chart... I set the X axis minimum value to zero. Then I used DataBindXY on the Chart.Series.First.Points to set the values passing two lists (first is a 0-based label list and other has the actual values).
Below is the result. As I highlighted by the red arrow the first column is truncated.
Microsoft made traversing the settings of a chart in the designer as simple as getting out of a maze, so I'm clueless about where to find some offset property to be set.
Edit:
Mine could be a possible duplicate of this question, but its answer is not clear to me, so I asked a new one.
If you set the X axis minimum value to -0.5, that should solve it.
GraphChart.ChartAreas[0].AxisX.Minimum = -0.5;
or try something like:
GraphChart.ChartAreas[0].AxisX.IntervalOffset = 0.5;
The reason is that the columns width is approximately 0.8 depending on the chart configuration so in your case they might span from 0.4 to 1.4, with a center point in 1