Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Script need running twice?

Status
Not open for further replies.

Alan Lowbands

Aerospace
May 17, 2017
274
Hi guys,
I dropped this in another thread but didn't get a reply.
I'm hoping it was just missed and that someone may know the answer.

The script below just alters some hole dimension properties but has to be run twice to complete everything.
Does anyone know why?

It was botched together from other bits of code so it's not very pretty

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

Sub CATMain()

Dim documents1
Set documents1 = CATIA.Documents

Set Document = CATIA.ActiveDocument

Dim selection1
Set selection1 = Document.Selection

Set Info = selection1.Item(1)

Dim Dimension1
Set Dimension1 = Info.Value

Dim DimTolValue
Set DimTolValue = Dimension1

Dim oTolType
Dim oDisplayMode
Dim oTolName
Dim oUpTolS
Dim oLowTolS
Dim oUpTolD
Dim oLowTolD

DimTolValue.GetTolerances oTolType, oTolName, oUpTolS, oLowTolS, oUpTolD, oLowTolD, oDisplayMode

oTolName = "TOL_NUM2"
oUpTolD = 0.2
oLowTolD = -0.0

DimTolValue.SetTolerances oTolType, oTolName, oUpTolS, oLowTolS, oUpTolD, oLowTolD, oDisplayMode

Dim DimDimValue
Set DimDimValue = Dimension1.GetValue

DimDimValue.SetFormatName 1, "ANS.DIMM"
DimDimValue.SetFormatPrecision 1, "0.100" 'precision

Dim oNoOff
oNoOff=InputBox ( "Enter No Off Holes" )
Dim oNoOffText
oNoOffText = "("& oNoOff &"x) "

Dim oBefore
oBefore =oNoOffText
Dim oAfter
oAfter =" THRO'"
Dim oUpper
'oUpper = "Upper"
Dim oLower
'oLower = "Lower"

Dimension1.GetValue.SetBaultText 1, oBefore, oAfter, oUpper, oLower

Dim myDim 'As DrawingDimension
Set myDim = CATIA.ActiveDocument.Selection.Item(1).Value
Dim myDimLine 'As DrawingDimLine
Set myDimLine = myDim.GetDimLine
myDimLine.DimLineGraphRep = catDimLine2Parts

MyDim.RestoreValuePosition()

End Sub
 
Replies continue below

Recommended for you

i change last line to
Code:
MyDim.RestoreValuePosition

and it works good for me in one shot

provide CATDrawing with at least one dimension if you can, so we test with same data.

what CATIA version do you use?

Eric N.
indocti discant et ament meminisse periti
 
It could be anything from r18 to r24.
I have been trying to get it to work on an r18 test drawing. The dimension is just a basic hole dim with nothing changed.
I've found it changes the basic dimension to the two part dim line and adds the tolerance but as zero. when I run it again it puts in the 0.0 +0.2 figures.
Ill post the drawing when I get on my cad machine.
I'll also change the line as suggested.

thanks itsmyjob :)
 
Can I throw in another one.
Just tried this code on a friends machine running r18 and the two part dim line wont work?
Why do scripts behave differently on different pc's?
It's probably the code I botched together but I just don't get why this would happen.
Is there anyway I can declare a single item, lets say "AlansDim = CATIA.ActiveDocument.Selection.Item" and then use that to change ALL the properties?
It's this part that I'm really struggling with. (I must be a bit thick)
cheers
 
ok my bad i run it twice and i see a difference... let me check

Eric N.
indocti discant et ament meminisse periti
 
ok not sure about what i say but it looks you need to set the tolerance type first so you can assign value after
so this works

Code:
DimTolValue.GetTolerances oTolType, oTolName, oUpTolS, oLowTolS, oUpTolD, oLowTolD, oDisplayMode

oTolName = "TOL_NUM2"

DimTolValue.SetTolerances oTolType, oTolName, oUpTolS, oLowTolS, oUpTolD, oLowTolD, oDisplayMode

DimTolValue.GetTolerances oTolType, oTolName, oUpTolS, oLowTolS, oUpTolD, oLowTolD, oDisplayMode
 
oUpTolD = 0.2

oLowTolD = 0#

DimTolValue.SetTolerances oTolType, oTolName, oUpTolS, oLowTolS, oUpTolD, oLowTolD, oDisplayMode

Eric N.
indocti discant et ament meminisse periti
 
Thanks again,
Will try that first thing.
Got to take the dog out :(

cheers
alan
 
Thanks itsmyjob,
worked a treat.
still don't understand why the two part line wouldn't work on my friends machine with R18.
It runs on mine so thanks again.

regards
Alan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor