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!

Select item and get dimension

Status
Not open for further replies.

gerlado

Mechanical
Oct 17, 2012
23
ES
Hi friends.

I've spent the last week, turning an idea, but more I try I can not get this macro.

My idea is to obtain the value of longitude as both a line of a circle.

It selecetelement2 I should apply, make a loop to read my part, select the item myself and I return in a msgbox the value of the longitude, but more I try, I always get error catscript


Can anyone help me please?
 
Replies continue below

Recommended for you

Hi,

More details it will be great for us to understand, also a sample part and what you tried in the code (maybe the code can be fixed).

If I understood, you want to measure the lenght of a circle in 3D, by selecting an edge of a feature?



Regards
Fernando

 
for example, this code get the minimun length of two lines: (Tested in Catia V5 R20)

Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = productDocument1.Selection
selection1.Clear

Dim InputObjectType(0), Status1
InputObjectType(0)="Edge"
Status1=selection1.SelectElement2(InputObjectType,"Select 1st Edge",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub

Dim reference1 As Reference
Set reference1 = selection1.Item(1).Reference

Dim TheSPAWorkbench As Workbench
Set TheSPAWorkbench = productDocument1.GetWorkbench("SPAWorkbench")

Dim TheMeasureable
Set TheMeasureable = TheSPAWorkbench.GetMeasurable(reference1)

selection1.Clear
Status1=selection1.SelectElement2(InputObjectType,"Select 2nd Edge",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub

Dim reference2 As Reference
Set reference2 = selection1.Item(1).Reference

x = TheMeasureable.GetMinimumDistance(reference2)

msgbox TheMeasureable.GetMinimumDistance(reference2)

End Sub


but I want know the distance of one line that i select in my view 3D, and if possible, also get the length of a part of circle that i select.

For example I have a rectangle, and in my view 3D select one edge, I want a Macro that show me in msgbox the length value of this line.



thank you very much for future responses
 
' ======================================================
' Purpose: Macro will measure any selected element from an active CATPart
' Usage: 1 - A CATPart must be active
' 2 - Run macro
' Author: ferdo (Disclaimer: You use this code at your own risk)
' ======================================================
Dim Language As String
Language="VBSCRIPT"

Sub CATMain()
Dim colDocum As Documents
Dim DocActivo As Document
Dim part1 AS Part

Dim sStatus As String
Dim mySelection As Selection
Dim InputObjectType(0)
InputObjectType(0) = "AnyObject"
Dim refBorde As Reference

Set DocActivo = CATIA.ActiveDocument
Set part1 = DocActivo.Part
Set mySelection = DocActivo.Selection

MsgBox "Select a boundary "
Status = mySelection.SelectElement2(InputObjectType, "Select a boundary or hit ESCAPE: ", True)
If (sStatus = "Cancel") Then
Exit Sub
End If

Set refBorde = mySelection.Item(1).Value
Dim TheSPAWorkbench As Workbench
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
Dim TheMeasurable As Measurable
Set TheMeasurable = TheSPAWorkbench.GetMeasurable(refBorde)

myLength = TheMeasurable.Length

MsgBox TheMeasurable.Name & " = " & myLength
mySelection.Clear

End Sub

Regards
Fernando

 
Many thanks Ferdo, the attachment is incredible
Works great in V5R20.

If I want I can hire you calculate an area, calculating the edges of longitude and altitude.

Thank you so much
 
Hello Ferdo.

Thank you very much for all the help provided in this forum
Admittedly, I'm using the google translator helps
Hope it's not a problem, only pretend to communicate of the best way.

I am a young engineer who is studying the world of macros in catia to work on my final-year.
Your help is very useful.
My current project is to extract the maximum information from one part and obtain the real price for manufacturing.

When everything is finished publishes the help I've provided during this journey and I can help other people in my situation
 
Hi,

No problem to use Google translator (I'm also using for other languages).

If you will search (in this forum or on Google) for CATIA Portable Script Center, you will find there few other macros which can be helpful for your project.

Regards
Fernando

 
Hi Again Ferdo
Thank you for the advice, i read the portable script center
I found a script that can aply material, it´s this:

Public Sub ApplyMaterial(calitateMat As String, oDoc As PartDocument, matName As String)
On Error GoTo err_treat
Dim matCatalogPath As String
CATIA.DisplayFileAlerts = False
Dim oMaterial_document As Document
Set oMaterial_document = CATIA.Documents.Read(matCatalogPath)

Dim oMaterial1 As Material
Set oMaterial1 = oMaterial_document.Families.Item(famNb).Materials.Item(matName)

Dim oManager As MaterialManager
Set oManager = oDoc.Part.GetItem("CATMatManagerVBExt")

oManager.ApplyMaterialOnPart oDoc.Part, oMaterial1, 0

oMaterial_document.Close
Exit Sub
err_treat:
'.......
end sub



But, in Catia V5R20, doesn´t work
When i try to execute this macro, catia give me a error of compilation microsoft visual basic script, line colum 14

Do you know why?

Thank you ferdo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top