×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Script need running twice?

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

RE: Script need running twice?

i change last line to

CODE --> VBA

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

RE: Script need running twice?

(OP)
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 :)

RE: Script need running twice?

(OP)
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

RE: Script need running twice?

ok my bad i run it twice and i see a difference... let me check

Eric N.
indocti discant et ament meminisse periti

RE: Script need running twice?

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 --> vba

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

RE: Script need running twice?

(OP)
Thanks again,
Will try that first thing.
Got to take the dog out :(

cheers
alan

RE: Script need running twice?

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources