I want to create a macro get properties of part & product in my design. I need to get partnumber of part.
When i selected in Tree or selected with "Product selection". It works with the same code:
Dim objSel
Set objSel = Catia.ActiveDocument.Selection
parNo= objSel.Item(1).Value.PartNumber
But it's not convenient.
I want to get PartNumber when I select any object (Edge, plane, surface...). By all the way, how can I get it?
Thanks & Best regards,
If you are selecting in an assembly you can use Leafproduct instead of Value
parNo = objSel.Item(1).LeafProduct.PartNumber
Related
I have a table name is Table1 with 2 fields which are Name and Married_Status.
For Name includes Names of the employees and for the Married_Status includes Yes or No.
The Question is: Can I show them in a report by 2 ways? first when the status is Yes 2 textboxes appear but if the status in No 1 textboxes appears?
I use Access 2016
If I am understanding you correctly you want to hide the Married_Status column if it is no. However this answer covers hiding other columns if I am misunderstanding. In short, this is called conditional formatting and is done by highlighting the control-clicking the format tab- then clicking conditional formatting. However, access can only conditionally format the text color, font, and background of a control. Further the default control for a yes/no variable is a checkbox and the checkbox allows no conditional formatting.
There are two work-arounds. First you can make the Married_Status text box invisible in all cases:
base the report on a query and replace Married_Status with a Calculated variable like:
Married_Status: IIf([Table1].[Married_Status]=True,"Married",Null)
If we use a text box for Married_Status and make it transparent we get:
When Married_Status is Null and the Married_Status textbox is transparent nothing shows. Unfortunately a checkbox shows even when the value is null.
The second work-around requires you know a lot about the data in advance and should only be done if the boss insists. You can build the report using VBA. For my sample data I know I have one page of 4 cases so I can avoid the detail section which limits me to one control for every instance of Married_Status and put as many controls as I need in the Header:
Then in the load event use vba to set the controls:
Private Sub Report_Load()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("Table1")
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
For i = 1 To 4
Me.Controls("Text" & i) = rs("EmployeeName")
If rs("Married_Status") = True Then
Me.Controls("Check" & i) = True
Else
Me.Controls("Check" & i).Visible = False
End If
rs.MoveNext
Next i
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
In FactoryTalk View SE I’m trying to set an objects name in VBA based on another value.
This works:
Dim PumpSP As Object
Set PumpSP = ThisDisplay.PumpSetpoint1
PumpSP.Vaule = 10
This doesn’t work:
Dim PumpSP As Object
Set PumpSP = "ThisDisplay.PumpSetpoint" & "1"
PumpSP.Vaule = 10
How do I get it to take a concatenated string?
Thanks.
How do I get it to take a concatenated string?
You don't, and you can't. PumpSP is an Object, not a String. The only thing you can ever Set it to, is an object reference.
This is very similar to, say, how you would access the controls on a UserForm:
Set box = Me.TextBox1
The reason you can get that object with a string, is because a form has a Controls collection that lets you provide a string, works out which control has that name, and returns the Control object for it:
Set box = Me.Controls("TextBox" & i)
So in your case to go from this:
Set PumpSP = ThisDisplay.PumpSetpoint1
I don't know what ThisDisplay is, but maybe it has a similar collection:
Set PumpSP = ThisDisplay.Controls("PimpSetpoint" & i)
If there's no collection that lets you retrieve items by name with a string literal, you're out of luck.
That is the hard part as we have paid support with Rockwell but they will not help with any VBA questions. Ok fine but there VBA commands and class are not like 90% of the Excel or MS Office VBA you find online. Anyway I was able to find the correct class member.
So this work for me:
Set PumpSP = ThisDisplay.FindElement("PumpSetpoint" & “1”) Thanks for all the help.
I am new to VBA coding..
help me in this situation..
I have a table like in sheet 1
Data table
& the user-form is like
User form
I need to display the searched data in this list-box...my logic which i have tried...
1) a variable which holds the text-box value
2) 1st tried with advanced filter but its not working
3) then tried with find function it also shows error..
I have tried but it does not display in list-box...it is my first working with list-box...thanks in advanced....
The details might well vary between Access and Excel, and the version of those tools ... I happened to use Access 2000 for this example.
In case you're not sure how to see what an icon is named: float the mouse cursor over it.
I opened the form in design view
I activated a toolbar that had the "Toolbox" icon
I selected "List box"
I clicked on the form and dragged a box shape. This made a caption box containing "List1:" and also a list box
I changed the caption to whatever matches the table I plan to use, which is "tblDomainName" hence "Domain Name:"
I opened up the properties for the list box and clicked in the "Row Source" area.
I typed "SELECT DomainName FROM tblDomainName ORDER BY DomainName" based on the table planned to use, so if your table were named "Stuff" then you'd type what's inside the double-quotes, here: "SELECT [Name] FROM Stuff ORDER BY [Name]" ... notice the square brackets in case "Name" is a reserved word that might cause confusion otherwise.
I changed to form "view" mode and clicked through the various values. They matched what's in my table, and they were sorted besides. Yay!
So, the above gets the list box basically working and gets you past your first hurdle ... as I understand it to be.
What's next? As to how you use that list box, and the selected value, to your benefit .... that depends on what the big picture is, so feel free to elaborate.
Does this help?
~Tanya
can you please show your codes you have tried? I'm sorry if I can't just comment on your question coz I'm still lacking in reputation. Thanks!
Please Try this code below:
Private Sub cmdSearch_Click()
Dim ws As Worksheet
Dim numRow As Integer
Dim found As Boolean
Set ws = ThisWorkbook.Worksheets("display")
For numRow = 1 To (ws.Range("A" & ws.Rows.Count).End(xlUp).Row)
If nameTxtBox.Value = ws.Range("A" & numRow).Text Then
nameList.AddItem (ws.Range("A" & numRow).Value)
prodList.AddItem (ws.Range("B" & numRow).Value)
saleList.AddItem (ws.Range("C" & numRow).Value)
found = True
Exit For
End If
Next numRow
If found = False Then
MsgBox "No Match Found!", vbCritical
nameList.Clear
prodList.Clear
saleList.Clear
End If
End Sub
userForm screen shot
Spread Sheet Screenshot:
hope this is what you want to do!
Thanks!
I have to move a probe like sphere between two parts such that the probe is in contact with both the parts. And I have to find the point of contact of the parts, measure their distance and make a fillet on the parts based on this distance. I have achieved in moving the sphere between the parts but the sphere is moving through the parts. So trying to move with respect to constraints
I am trying to automate the manipulate tool in Catia Product.
Is there any command or method exist to move a part with respect to contraints in Catia using vba ?
Or
Is there any way to find the clash between two parts using vba ?
Looking Forward for a solution.
Thank you!!!
Here is a link where you can find a solution for clash.
OK, I got the idea, you want to see the code here :-)
To compute clash in a CATScript:
Sub CATMain()
' get root product of document
Dim RootProd As Product
Set RootProd = CATIA.ActiveDocument.Product
' retrieve selection object of active document
Dim objSelection As Selection
Set objSelection = CATIA.ActiveDocument.Selection
' get two selected objects
If (objSelection.Count2 <> 2) Then
MsgBox "Before running the script you must select two products to compute clash for", vbOKOnly, "No products selected"
Exit Sub
End If
Dim FirstProd As Product
Dim SecondProd As Product
Set FirstProd = objSelection.Item2(1).Value
Set SecondProd = objSelection.Item2(2).Value
' create groups for clash computation
Dim objGroups As Groups
Set objGroups = RootProd.GetTechnologicalObject("Groups")
Dim grpFirst As Group
Dim grpSecond As Group
Set grpFirst = objGroups.Add()
Set grpSecond = objGroups.Add()
' add selected products to groups
grpFirst.AddExplicit FirstProd
grpSecond.AddExplicit SecondProd
' get access to Clashes collection
Dim objClashes As Clashes
Set objClashes = RootProd.GetTechnologicalObject("Clashes")
' create new clash
Dim newClash As Clash
Set newClash = objClashes.Add()
' set new clash to be computed between two groups (two selected products)
newClash.FirstGroup = grpFirst
newClash.SecondGroup = grpSecond
newClash.ComputationType = catClashComputationTypeBetweenTwo
' compute clash
newClash.Compute
End Sub
I am trying to edit the part dimension in CATIA by changing the dimension values in the design table in the excel file. Everytime when i change the values i should manually update the part model. I want to update it automatically through VBA code and save it.
I tried
Sub CATMain()
CATIA.DisplayFileAlerts = False
Dim part As PartDocument
Set part = CATIA.ActiveDocument
part.Update
part.SaveAs "D:\E\CSE\.....\Part2.CATPart"
End Sub
and it is not working.
How can we update and save it??
You called ".Update" on the Document object, not the Part-object!
Answer is:
Dim part As PartDocument
Set partDoc = CATIA.ActiveDocument
partDoc.Part.Update
Your Code is correct and it should be working. Do you get any errors?
If you simply want an automatic update try to change your settings ...
Goto Tools->Options Then in the options dialog, goto Infrastructure Tree Node, and expand that and goto Part Infrastructure. Now on the right pane in the General Tab, Make sure you select Automatic for the Updates.
If this doesn't work you could try to the Part.UpdateObject objectToUpdate method to update the individual feature(s) that need to be updated.