Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import points from Excel and connect them with lines. 2

Status
Not open for further replies.

cimmerian

Mechanical
Feb 2, 2010
12
PT
Hi,

I was able to import a set of points from Excel by means of a macro I found on the internet. I have uploaded an image of the imported points in CATIA:

Now I want to know if there is a way in CATIA to connect all the points automatically, generating a closed profile, without having to do it manually, since I have more than 100 points?

I tried the macro that comes with CATIA called "GSD_PointSplineLoftFromExcel", but the option I have is to connect points with a spline. Since when connecting the points a closed profile is obtained I get an error every time I try that with spline.

Does anyone know how I can do that in CATIA or knows of a macro that can do that?

Many thanks!
Filipe
 
Replies continue below

Recommended for you

Just an update to my prevous post, the error i got when using the spline function from the macro "GSD_PointSplineLoftFromExcel" was due to the fact that I had repeated points on my profile and not to being a closed profile.

However I still don't know if there is a way to edit this macro so as to connect automatically the points, for instance, with a polyline? I'm using this feature in CATIA to manually connect all the point and generate a closed profile, but this takes forever when I have hundreds of points!

Any help would be much appreciated!

Many thanks!
Filipe
 
Have you considered doing it in two stages, i.e.two open splines, then join them?
 
Hi, and thank you for your response.

My main question is not how I can connect the points with the spline. The question is I have a set of points in Excel worksheet that I import to CATIA and I want to connect them with a line automatically. Since I have hundreds of points connecting them manually using polyline is a time consuming task.

So I would like to know if anyone knows of a macro that can import a set of points from Excel to CATIA and connect them automatically? (my knowledge in the development of macros for CATIA is virtually non existent).

Thank you once again for your response and apologize if I was not clear in my previous posts.

Many thanks!
Filipe
 
My knowledge is even less than virtually non-existent, however I do have this macro. It is for inputting points, but I don't know how to work it, so I can't tell if when you run it, does it give an option to connect the points by lines? Sorry, that's the best I can do.


**********************************
'Option Explicit

Sub CatPoints()

Dim Rng As Range
Dim i As Long
Dim j As Long
Dim CATIAPts()
Dim CheckVal As Boolean
Dim xcoord As Double, ycoord As Double, zcoord As Double
Dim Partname As String
Dim CATIA As Object
Dim Excel As Object
Dim Documents As Object

' On Error Resume Next

' Create the CATIA Application Object
Set CATIA = CreateObject("Catia.Application")
' Set CATIA = GetObject(, "Catia.Application")
' Make a new CATIA part
Set Documents = CATIA.Documents
Set PartDocument0 = Documents.Add("Part")

'Excel.WindowState = 1
AppActivate ThisWorkbook.Application.Caption

' Enter the name of the model to save
Partname = InputBox(prompt:="Enter CATIA Part Name to Save Points As", Title:="CATIA Part Name")

' Creating new part
Set Part = PartDocument0.Part
Set hybridBodies1 = Part.hybridBodies
Set hybridBody1 = hybridBodies1.Add()
Set hybridShapeFactory1 = Part.HybridShapeFactory
Set hybridBody1 = CATIA.ActiveDocument.Part.hybridBodies.Item("Open_body.1")

CATIA.ActiveWindow.WindowState = 0

Set Rng = Application.InputBox(prompt:="Select Range of Points", Title:="CATIA Point Definition", Type:=8)
If Rng Is Nothing Then
MsgBox "Operation Canceled"
Exit Sub
Else
Rng.Select
End If

nbrow = Rng.Rows.Count
nbcol = Rng.Columns.Count

If nbcol <> 3 Then
response = MsgBox(prompt:="You must select 3 Columns - X, Y, Z", Buttons:=vbCritical, Title:="Selection Error!")
Exit Sub
End If

nopts = 0
For i = 1 To nbrow

CheckVal = IsEmpty(Rng.Cells(i, 1).Value)

If CheckVal = False Then
Application.StatusBar = "Processing Point " & Rng.Cells(i, 1).Value
xcoord = Rng.Cells(i, 2).Value * 25.4
ycoord = Rng.Cells(i, 3).Value * 25.4
zcoord = Rng.Cells(i, 4).Value * 25.4

Set hybridShapePointCoord1 = PartDocument0.Part.HybridShapeFactory.AddNewPointCoord(xcoord, ycoord, zcoord)
hybridBody1.AppendHybridShape hybridShapePointCoord1

nopts = nopts + 1

Else
Application.StatusBar = "Line " & i & " not processed"

End If

Next i

PartDocument0.Part.Update
PartDocument0.SaveAs (Partname)

CATIA.Application.Quit
Set CATIA = Nothing

Application.StatusBar = False
Message = nopts & " Points Processed." & " Model Written to: " & Partname
MsgBox Message

End Sub
 
Hi, I created a macro in CATIA with your code, but when trying to run it I get a compile error saying "User-defined type not defined". I guess other steps are required to put this working, but my current knowledge of it is not enough.

However, by looking at the code you provided and comparing it with other macros I have, I think it only reads points, because there is no function call to create lines between the points.

Nonetheless thank you very much for your help. I really appreciate it!

Many thanks!
Filipe
 
Hi Filipe,

Your final goal is to create a mesh with those points and lines or just a closed profile?

Regards
Fernando
 
Hi, thank you very much for your reply!

I have a set of point (between 200 and 300) in Excel and my goal is to import them to CATIA and connect them automatically with a line to create a closed profile.

These points are the vertices of a 2D polygon, so when I connect them I obtain a closed profile.

My goal is then to develop a macro, that can read the points automatically from Excel and import them to CATIA. After this it also connects them automatically.

To connect them I just have to connect each point sequentially with a line (e.g.: connect point 1 with point 2, point 2 with point 3,...,and the last point with point 1 again, to obtain a closed profile).

Thus far I am able to import the points to CATIA, but the macro I use doesn't connect them with a line. So I have to do it manually with the the "polyline" feature, from the "Wireframe and Surface Design" workbench. But this task is very time consuming, because I have hundreds of points.

If you know of a macro that can do this or can give me any hints on how to modify an existing macro to achieve this, any help would be much appreciated!

Many thanks!
Filipe
 
Hi,

Following my last questions I started learning a bit about vba and was able to create my own macro in Excel, from examples that I found on this forum and others.

I am sending the code in a ".txt" file and an image with an example of how I set the Excel worksheet.

Basically this macro reads the x, y, z coordinates from columns 2, 3 and 4, respectively, in the Worksheet (these can be changed in the code) and imports the points to a CATIA Part (you need to have an open part before running the macro in Excel). These points represent the vertices of a 2D polygon, whose geometry I wanted to import to CATIA and then create a solid from it.

So after importing the points, it creates a closed profile with all the points, taht is ready to be used with the "Pad" feature from CATIA.

Since this is my first project in vba, it is very simple, and I do not do any error checking, in case you do something wrong. I am just sharing this, in case someone else has a similar problem or just wants to learn a bit more about vba.

Thank to all who replied!
Filipe
 
 http://files.engineering.com/getfile.aspx?folder=337511a9-17af-43f5-8620-39237b8f4395&file=Import_points_from_excel_and_create_polyline.zip
Just before I read your last post, I just remembered many years ago I had to program a CNC machine to cut an inlet manifold for a race car.

I needed to get it done in a hurry and I hadn't time to learn Pro E. I had lots of points in Excel provided by the flow analysis bloke, so I decided I would create the macro in Excel, so that Excel actually output all the linear moves for me. I was about to suggest that sloution might be an option for you, but you got there already. All the best
 
Cimmerian, a start for you as you learned enough to get a solution and share it with us.

Never stop learning...

Eric N.
indocti discant et ament meminisse periti
 
Hi,

MRSSPOCK, itsmyjob, thank you for your words. Indeed this was a new door that has opened to me. I hope to continue to improve and learn more.

Thank you once again for your contributions!
Filipe
 
Hi,

A star from me also. I've asked you that question because accidentally I was trying to understand how the attached catvba is working (the original catvba you can find it on gtwiki).

You can take a look at him, is a nice piece of work. I've also attached the additional software which is used by CATIA to create the mesh (obviously, is not your case).

Regards
Fernando
 
 http://files.engineering.com/getfile.aspx?folder=586e5ee6-5c4f-4b2b-8bd4-50a6e00c5a84&file=qhull.zip
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top