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!

Decimal places ???

Status
Not open for further replies.

Alan Lowbands

Aerospace
May 17, 2017
274
GB
Hi,
Can anyone help please.
I'm running a macro that extracts the sizes of a part from the properties boxes to paist on a drawing.
Length width and height.
I can get them with no problem but its returning the sizes to around 7 or 8 decimal places.
Is there an easy way to set then to 3 ?
I'm a bit desperate :(
Fankenstien code below (please don't laugh to hard)

-------------------------------------------------------------------------------------------------------------

Sub CATMain()


'-----------------Select body

Dim partDocument1 'As Document

Set partDocument1 = CATIA.ActiveDocument

Dim part1 'As Part

Set part1 = partDocument1.Part

Dim oSel 'as Selection

Set oSel = partDocument1.selection

Dim Filter(0)

Filter(0)="Body"

Dim F_Body 'as object

F_Body=oSel.selectelement2(Filter, " Select Body in which you want to add", False)

Dim bodies1 'As Bodies

Set bodies1 = part1.Bodies

Dim body1 'As Body

Set body1 = bodies1.Item(oSel.item(1).value.name)

'--------------Short Name

Set product1 = partDocument1.GetItem("1")
oShortName = Split(CATIA.ActiveDocument.Name,".")(0)


sShortString = oShortName



'-------------------------------------------------------------------------------------------------------------------------

'------------------------------Material from model
Dim productDocument1 'As Document
Set productDocument1 = CATIA.ActiveDocument
Dim product1
Set product1 = productDocument1.Product
Dim parameters1
Set parameters1 = product1.Parameters
Set product1 = product1.ReferenceProduct
Dim oMat
oMat = parameters1.Item("MATERIAL").Value
'MsgBox oMat
oStock = parameters1.Item("Definition").Value
'MsgBox oStock
'--------------------------------------------------------------------------------------------------------------------------
'------------------------------Length from model
'Dim productDocument1 'As Document
'Set productDocument1 = CATIA.ActiveDocument
'Dim product1
'Set product1 = productDocument1.Product
'Dim parameters1
'Set parameters1 = product1.Parameters
'Set product1 = product1.ReferenceProduct
Dim oLength
oLength = parameters1.Item("Length").Value

'--------------------------------------------------------------------------------------------------------------------------
'------------------------------WIDTH from model
'Dim productDocument1 'As Document
'Set productDocument1 = CATIA.ActiveDocument
'Dim product1
'Set product1 = productDocument1.Product
'Dim parameters1
'Set parameters1 = product1.Parameters
'Set product1 = product1.ReferenceProduct
Dim oWIDTH
oWIDTH = parameters1.Item("Length").Value

'--------------------------------------------------------------------------------------------------------------------------
'------------------------------HEIGHT from model
'Dim productDocument1 'As Document
'Set productDocument1 = CATIA.ActiveDocument
'Dim product1
'Set product1 = productDocument1.Product
'Dim parameters1
'Set parameters1 = product1.Parameters
'Set product1 = product1.ReferenceProduct
Dim oHEIGHT
oHEIGHT = parameters1.Item("Length").Value

'--------------------------------------------------------------------------------------------------------------------------

'------------------------------Stock from model
'Dim productDocument1 'As Document
'Set productDocument1 = CATIA.ActiveDocument
' Dim product1
'Set product1 = productDocument1.Product
'Dim parameters1
'Set parameters1 = product1.Parameters
'Set product1 = product1.ReferenceProduct
' Dim oStock
'oStock = parameters1.Item("Definition").Value
'MsgBox oStock
'--------------------------------------------------------------------------------------------------------------------------


'------------------------------Drawing sheet

Set documents1 = CATIA.Documents

Set drawingDocument1 = documents1.Add("Drawing")

drawingDocument1.Standard = catISO

Set drawingSheets1 = drawingDocument1.Sheets

Set drawingSheet1 = drawingSheets1.Item("Sheet.1")

'drawingSheet1.PaperSize = catPaperA0

drawingSheet1.Scale = 1.000000

'drawingSheet1.Orientation = catPaperLandscape

Set drawingViews1 = drawingSheet1.Views

Set drawingView1 = drawingViews1.Add("AutomaticNaming")

Set drawingViewGenerativeLinks1 = drawingView1.GenerativeLinks

Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior

drawingViewGenerativeLinks1.AddLink body1

drawingViewGenerativeBehavior1.DefineFrontView 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000

drawingView1.x = 594.500000

drawingView1.y = 420.500000

drawingView1.Scale = 1.000000

Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior

drawingViewGenerativeBehavior1.Update

drawingView1.Activate

'-------------------Hide axis

Dim selection1 'As Selection
Set selection1 = drawingDocument1.Selection
selection1.Search "Name=*HDirection*,all"
Set visPropertySet1 = selection1.visProperties
VisPropertySet1.SetShow 1
selection1.Clear
selection1.Search "Name=*VDirection*,all"
Set visPropertySet1 = selection1.visProperties
VisPropertySet1.SetShow 1
selection1.Clear
selection1.Search "Name=*Origin*,all"
Set visPropertySet1 = selection1.visProperties
VisPropertySet1.SetShow 1
selection1.Clear

CATIA.StartCommand "Fit All In"


'---------------------Text Box

Dim FullName
Dim DrwNo

FullName = partDocument1.Name
strNewNumber = FullName
sString = strNewNumber


Dim oQty
oQty=InputBox ( "ENTER QTY" )


Dim oDoc
Dim oCurrentView

Dim oTextToEnter
oTextToEnter = sShortString & vbCrLf & "TOLERANCE - " & " SEE TABLE" & vbCrLf & "ROUGH STOCK SIZE - " & oStock & " mm" & vbCrLf & oLength/25.4 & "oWIDTH" & "oHEIGHT" & vbCrLf & "MATERIAL - " & oMat & vbCrLf & "QTY - " & oQTY & "-OFF"
Dim oText1

Set oDoc = CATIA.ActiveDocument

Set oCurrentView = CATIA.ActiveDocument.sheets.ActiveSheet.Views.ActiveView

dim dXY(1)
dim sSelType(0)
set oDoc = CATIA.ActiveDocument
set oSel = oDoc.Selection
oSel.Clear
sSelType(0) = "Point2D"
sSelStatus = oSel.IndicateOrSelectElement2D("Select a point or click", _
sSelType, false, false, false, bObjSelected, dXY)
if sSelStatus = "Normal" then
if bObjSelected then
'An existing point was selected, get its coordinates
set oPoint = oSel.Item(1).Value
oPoint.GetCoordinates dXY
end if
end if
oSel.Clear

Set oText1 = oCurrentView.Texts.Add(oTextToEnter, dXY(0), dXY(1))

'oText1.SetFontName 0, 0, "Arial (TrueType)"
'oText1.SetFontSize 0, 0,5

'-------------------------------UpDate



drawingViewGenerativeBehavior1.Update

drawingView1.Activate



'--------------copy to clipboard for save-------------------------------------

Dim oNameSave
oNameSave = sShortString & "_" & oItem

Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("clip")

Set oWrite = oExec.stdIn

oWrite.WriteLine oNameSave
oWrite.Close

'----------------------------------------------------------------------


End Sub
 
Replies continue below

Recommended for you

Hi,
Sussed that bit but got a weird problem.
The parameters were named "Length" "WIDTH" & "HEIGHT"
When I use the code below it picks up the WIDTH value for both Length and WIDTH ?
Any ideas why ?
Any help would be appreciated thanks

-------------------------------------------------------------------------------------------------

Dim productDocument1 'As Document
Set productDocument1 = CATIA.ActiveDocument
Dim product1
Set product1 = productDocument1.Product
Dim parameters1
Set parameters1 = product1.Parameters
Set product1 = product1.ReferenceProduct

Dim oMat
oMat = parameters1.Item("MATERIAL").Value

Dim oStock
oStock = parameters1.Item("Definition").Value

Dim oLength
oLength = parameters1.Item("Length").Value

Dim oWIDTH
oWIDTH = parameters1.Item("WIDTH").Value

Dim oHEIGHT
oHEIGHT = parameters1.Item("HEIGHT").Value

Dim oLength2
Dim oLength3
oLength2 = oLength'/25.4
oLength3 = round (oLength2 ,3)
Msgbox oLength3

Dim oWIDTH2
Dim oWIDTH3
oWIDTH2 = oWIDTH'/25.4
oWIDTH3 = round (oWIDTH2 ,3)
Msgbox oWIDTH3

Dim oHEIGHT2
Dim oHEIGHT3
oHEIGHT2 = oHEIGHT'/25.4
oHEIGHT3 = round (oHEIGHT2 ,3)
Msgbox oHEIGHT3
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top