Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Macro: Parameter, Remove constant.

Status
Not open for further replies.

ChrisHod

Aerospace
Jun 9, 2014
4
Hi All,

I've recently started creating a few macros to help my team with some of the more tedious aspects of our work within CATIA. Mainly to aid with the Airbus HnF tool.

One of the Parameters generated by the tool is set to "Constant" by default, as a means to "lock" the parameter. Does anyone know the correct code term I would use to remove the "Constant" Lock, change the value and then reapply the "Constant" Lock?

I've been trawling the net/forums for any hint as to the correct syntax for setting constant to false on a parameter but to no avail!!!!

I thought it would be simple as:

Set parm = objShape.GetParameter("Synchronized")

parm.Constant = false

parm.Value = "True"

Any help would be much appreciated.

Cheers

Chris
 
Replies continue below

Recommended for you

one possible solution... not the best.. but works (sometimes)..
hopefully someone can share a better method.


Code:
Sub Lock_Modify_Unlock()

Dim oActiveDoc As Document
Set oActiveDoc = CATIA.ActiveDocument
oActiveDoc.Activate
Dim oParameters As Parameters
Set oParameters = oActiveDoc.Part.Parameters

Set ostrPar = oParameters.Item("Synchronized")

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

selection1.Add ostrPar

Dim objShell As Object
Set objShell = CreateObject("WScript.Shell")


CATIA.StartCommand ("UnLock")
Application.Wait 1000
objShell.SendKeys "{ENTER}"

ostrPar.Value = "modified"

selection1.Clear
selection1.Add ostrPar


CATIA.StartCommand ("Lock")
Application.Wait 1000
objShell.SendKeys "{ENTER}"



End Sub

______

Alex ,
 
Thanks for your replies guys!

Ferdo, I've attached screen grab of the node/parameters I’m trying to modify. The parameter in question is "Sychronized". The node itself is created by a macro called HnF which we use for creating Holes/Fastener geometry and info. Each node is populated with these parameters. When a new fastener is generated the parameters are locked by default (though not visibly) There is an unlock function in the toolbar that allows you to then edit all the parameters EXCEPT the "Synchronized" parameter. We have the code segment to run the unlock function for the rest of the parameters but it does not unlock "Synchronized".

Code:
Sub SetSyncToTrue( objDoc )                                                                               
    Set objSel = objDoc.Selection                                                                         
                                                                                                          
    For i=1 To objSel.Count2                                                                              
        Set objItem = objSel.Item2(i)                                                                     
        Set objShape = objItem.Value                                                                      
        If CheckHnF(objShape) Then                                                                        
            Set parm = objShape.GetParameter("Synchronized")                                              
            
'''Suppress read-only (This turns off the Parameters Invisible Lock)                                                                         
           If parm.ReadOnly Then
                AIFHnFGsdLockUnlockParametersHdr
               parm.SetEnumerateValues(Array("DummyVal"))
               parm.SuppressEnumerateValues()
           End If                                                                                 
             
          ''' This is where I need to specifically unlock "Snychronized"                                                    				
              parm.Lock = false
			
               End If  
                                                                                                                                                                                    
    Next                                                                                                      
End Sub

Garzar, I simply mean the parameter is locked; the value has been set to "constant". I realise this is the normal way in which a parameter is locked but the macro that creates these parameters does not lock the others in this manner, the parameter can be locked and not have the "Constant" box selected in the parameter properties.

Alex, Thanks for the code but unfortunately I’m editing a .catvbs file, as far as I’m aware the CATIA.StartCommand doesn’t work in this kind of code? Although I’m willing to be corrected on that!
 
 http://files.engineering.com/getfile.aspx?folder=d95423a4-47ed-40e8-9671-946109c5597a&file=Tree.jpg
Thanks Fernando,

For us Synchronized is always shown as locked, its value remains "True" until you edit any of the other parameters, at which point it changes to "false" automatically. Our Standard states this should always read "True", but when we create "drill_only" nodes we have no choice but to edit the other parameters to make sure they are populated correctly. Hence the requirement for us to change the "Sychronized" parameter back to "True". Doing this manually for a model that conatains 100's of fasteners is painfully tedious and time consuming. Automating this would be a real bonus for us!
 
A Quick update,

So I'm still wrestling with this macro in between jobs. I read yesterday that parameter unlock isnt possible via .catvbs, you have to use .CATScript.

I tried Alex's code but that didnt seem to work, with some digging online I found this code:

Code:
Sub CATMain()

Set objPart = CATIA.ActiveDocument.Part

'Select the parameter
 Set objSel = CATIA.ActiveDocument.Selection
 objSel.Clear
 objSel.Add objPart.Parameters.Item("Synchronized")

'To unlock
 CATIA.StartCommand "Unlock"
 
'To lock
 'CATIA.StartCommand "Lock"
 
'Clear the selection
 objSel.Clear

End Sub

This works in that it initiates the unlock process, One step closer!!!! But now the issue is when the parameter unlocks a pop up window asks to confirm the unlock. Can someone help me finish this code so that it will "SendKeys" to enter after the unlock, change the parameter value to "true" then re-lock (will require a SendKeys command again)?

Ideally i'd also want to be able to run this script within an assembly applying the script to all items selected.

If anyone can help me out with this it'd much appreciated, my knowledge of CATIA.StartCommand is even less than my knowledge of CATvbs!!!

Cheers

Chris
 
Hi

Chris, I would do something else, select all parameters by name in one shot, run the command Unlock and let designer push OK button, all will be unlocked in a single step. You can change then parameters value in a loop (another macro) and a third macro to lock again.

Of course all this can be done also in catvba (not catvbs) with sendkeys as Alex already shown but in my experience this is not the best idea. You can do sendkeys command in catscript or catvbs calling a vbs file from outside CATIA but again, I wouldn't recommend (search forum, there is an example).

In catvba you need to do something like bellow to use sendkeys (and let CATIA work, don't do something else, otherwise you can change the window and sendkeys will be send to another window).

CATIA.StartCommand ("Unlock")

PauseTime = 3 ''play with the figure here...
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
TotalTime = Finish - Start

CATIA.RefreshDisplay = True
SendKeys "{Enter}", True



Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor