Script need running twice?
Script need running twice?
(OP)
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
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





RE: Script need running twice?
CODE --> VBA
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?
indocti discant et ament meminisse periti
RE: Script need running twice?
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 :)
RE: Script need running twice?
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
RE: Script need running twice?
indocti discant et ament meminisse periti
RE: Script need running twice?
so this works
CODE --> vba
indocti discant et ament meminisse periti
RE: Script need running twice?
Will try that first thing.
Got to take the dog out :(
cheers
alan
RE: Script need running twice?
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