How to translate a part using CATscript in CATIA? - vbscript

I working with CATscript in CATIA to create Macros. I am trying to create a CATscript to translate a feature in CATIA.
When I run the CATscript I Should select the feature that should be translated and and the feature will be translated.
But I am getting an runtime error Type mismatch:'part1.CreateReferenceFromObject'
I could not find the solution for this problem.
Looking forward for your help.
Thanks in Advance.
Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set hybridShapeFactory1 = part1.HybridShapeFactory
Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(1.000000, 0.000000, 0.000000)
Set hybridShapeTranslate1 = hybridShapeFactory1.AddNewEmptyTranslate()
Set UserSel = partDocument1.Selection
Dim type1(0)
type1(0) = "HybridShape"
'--------------------------------------
'Dim input As Object
input = UserSel.SelectElement2(type1, "select input.", False)
Set reference1 = part1.CreateReferenceFromObject(input)
hybridShapeTranslate1.ElemToTranslate = reference1
hybridShapeTranslate1.Direction = hybridShapeDirection1
hybridShapeTranslate1.DistanceValue = 1.000000
Set hybridBody2 = hybridBodies1.Item("Geometrical Set.3")
hybridBody2.AppendHybridShape hybridShapeTranslate1
part1.InWorkObject = hybridShapeTranslate1
part1.Update
End Sub

your problem is that you are trying to create a reference from a Selection object.
input = UserSel.SelectElement2(type1, "select input.", False)
This returns the type Selection. You can dig into the input and get the actual object that you select.
try:
Dim myReference as Reference
Dim myExpectedObject as HybridShape 'or use variant
Set mySelectedObject = input.Item2(1).Value 'this will grab the first item from the selection collection
set myReference = part1.CreateReferenceFromObject(mySelectedObject)
'continue the rest of your code
Also, you should always clear the selection before you use a user selection as a good habit.
UserSel.Clear 'call this before you call a SelectElement selection function

Related

get contact information for a particular email address

I am trying to write a script that would
go through a list of email addresses from my domain
for each of these emails addressess get the display name and job title
output the email, display name, job title to a csv file
I am sure this is fairly simply, the only problem that I have here is that I have no idea how to access the contact card of a contact.
How do I pass the strAddress variable to a olContactItem object?
EDIT:
To improve the question - I don't know how can I view the contact of the existing user#mydomain.com from a list of email addresses in a csv file (not added to my contacts list or anything)
The code I have so far:
Const olContactItem = 2
strEmail = "user#mydomain.com"
set fso = CreateObject("Scripting.FileSystemObject")
set appOutlook = CreateObject("Outlook.Application")
Set MyItem = appOutlook.CreateItem(olContactItem)
With MyItem
.Email1Address = strEmail
.jobTitle = strJobTitleVar
End With
I need to open the addess book page of that person, extract the values of Job Title and Display Name to relevant variables. However, I get stuck, because I get to a point where I am rather adding a new contact than viewing the existing person's info.
Is this more clear? How can I search through the address book for a particular person's info?
Answering my own question - this seems to be doing everything I need:
strInputEmail = objInputFile.ReadLine
set appOutlook = CreateObject("Outlook.Application")
set objNameSpace = appOutlook.GetNameSpace("MAPI")
set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)
Set objContact = objContacts.Items.Find("[IMAddress] = """ & strInputEmail & """")
strFullName = objContact.FullName
strJobTitle = objContact.JobTitle
strBusinessAddress = objContact.BusinessAddress
msgBox strFullName & strJobTitle & strBusinessAddress
It reads the inputfile, gets the email address as a variable, finds the person, gets the particular info as variables.
Thanks for help anyway!
Try something along the following lines. To see what the other properties and their DASL names are, look at the live GAL objects using OutlookSpy (I am its author): either click IAddrBook button and drill down the container hierarchy or click IMAPISession | QueryIdentity to see the current user or (if you have a message with a particular recipient) click IMessage, go to the GetRecipientTable table, double on the recipient.
Once you have the IMailUser window, select the property that you need and look at the DASL edit box.
Const olContactItem = 2
strEmail = "user#mydomain.com"
set fso = CreateObject("Scripting.FileSystemObject")
set appOutlook = CreateObject("Outlook.Application")
set NS = appOutlook.GetNamespace("MAPI")
NS.Logon
set Recip = NS.CreateRecipient(strEmail)
Recip.Resolve
set AE = Recip.AddressEntry
Set MyItem = appOutlook.CreateItem(olContactItem)
With MyItem
.Email1Address = strEmail
'read PR_TITLE property
.jobTitle = AE.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3A17001F")
End With

How to add column to FoxPro file using DAO

I need to add some columns to a FoxPro 2.6 DBF file using DAO in VB6.
If the data were in an .MDB file, I know this would work. Here is a code snippet which I use for .MDB:
Set tdfCoParms = mDBParms.TableDefs(CoParms)
tdfCoParms.Fields.Append tdfCoParms.CreateField("CoName", dbText, 30)
Am unsure if this works for FoxPro. (I have not tried)
Is this possible? There is a possible alternative - which I know would work, but which is not so convenient - by starting with an empty table of the correct structure, then copying across the records from the existing populated file, using INSERT of a SELECT from this.
Thank you #wqw, as your solution certainly works.
This was my first alternative, which worked:
Create an empty file/table with the desired columns.
Copy this file to "test.dbf".
Insert records from the populated data file "link" into this.
Dim dbsWork As Database
Dim qrd As DAO.QueryDef
Dim szSqlString As String
Set dbsWork = OpenDatabase(szWorkDir, False, False, "FoxPro 2.5")
Dim szFieldList As String
szFieldList = "field1, field2, field3"
szSqlString = "INSERT INTO test SELECT " & szFieldList & " FROM link"
Set qrd = dbsWork.CreateQueryDef("", szSqlString)
qrd.Execute
Set qrd = Nothing
Set dbsWork = Nothing
But the following based on #wqw's suggestion is much better, as no predefined file is required
Private Sub Test1()
Dim dbsWork As Database
Dim qrd As DAO.QueryDef
Dim szSqlString As String
Set dbsWork = OpenDatabase(MyDataBasPath, False, False, "FoxPro 2.5")
Dim szFieldList As String
szSqlString = "ALTER TABLE work.dbf ADD COLUMN fred VARCHAR(30)"
Set qrd = dbsWork.CreateQueryDef("", szSqlString)
qrd.Execute
Set qrd = Nothing
Set dbsWork = Nothing
End Sub

How to add data to a specific column in an existing excel file using VBScript

I'm currently doing automation testing and need to write a dynamic value to an existing excel document in a specific column, this is what I have so far. Forgive I'm a novice
Sub WriteTRNtoExcelDoc
Dim fileName, sheetName
fname = "<Path_To_The_File>"
sheetName = "Sheet1"
Set app = Sys.OleObject("Excel.Application")
Set book = app.Workbooks.Open(fname)
Set sheet = book.Sheets(sheetName)
' What do I do next to add a value to a specific column or cell in this
' spreadsheet?
End Sub
Thanks in advance!
You create an Excel instance in a VBScript with
CreateObject("Excel.Application")
An already running Excel instance can be grabbed with
GetObject(, "Excel.Application")
In a worksheet you can access cells by using the Cells property:
Set app = CreateObject("Excel.Application")
app.Visible = True
Set book = app.Workbooks.Open(fname)
Set sheet = book.Sheets(sheetName)
sheet.Cells(2,3).Value = "foo"
Edit: If you need to find the first empty cell in a given column, you can use something like this:
row = 1
Do Until IsEmpty(sheets.Cells(row, 3).Value)
row = row + 1
Loop
sheet.Cells(row, 3).Value = RemPropValue

deleting a record in linq to sql (vb.net) what is wrong with my code?

I am getting the correct Employee Id in the VarEmpID variable. When I click on delete
It is giving me
Unable to cast object of type 'System.Data.Linq.DataQuery`1[my name space]' to type 'namespace'.
enter code here
Protected Sub radGrid1_DeleteCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles radGrid1.DeleteCommand
Dim VarEmpId As String = (CType(e.Item, GridDataItem)).OwnerTableView.DataKeyValues(e.Item.ItemIndex)("EmpId").ToString()
Using dc1 As New EmployeesDataClassesDataContext()
Dim EmployeeEntry = (From p In dc1.Employees
Where (p.EmpId = VarEmpId)
Select p)
dc1.Employees.DeleteOnSubmit(EmployeeEntry)
dc1.SubmitChanges()
Dim queryResults = (From queryItem In EmployeeEntry Select queryItem).ToList()
If queryResults.Any Then
radGrid1.DataSource = queryResults
radGrid1.DataBind()
End If
End Using
End Sub
dc1.Employees.DeleteOnSubmit(EmployeeEntry)
That method expects an Employee instance. Instead, you passed in an employee query.
Dim EmployeeEntry = ( query )
This is a query, not an entry. Consider calling Enumerable.First to get the first result of the query, and then deleting that.
Modified added Dim EmployeeEntry = (From p In dc1.Employees Where (p.EmpId = VarEmpId) Select p).singleorDefault() After that commented out the queryresults part and binded data again it solved my problem. – SmilingLily

Adding a new user to CRM 4.0 using sdk

Does anyone have sample code to add a new user to CRM 4.0 using sdk?
I have code that creates users for us based on users in another system so I can't exactly paste it all here - most of it wouldn't make sense to you - but this is the core of it:
[In VB sorry :-) - also when posting VB here I find I need to use '//' to indicate a comment to make the formatting correct]
Public Sub CreateNewUser()
Dim s as mscrm.CrmService = GetMyService()
Dim newUser as New mscrm.systemuser()
With newUser
.domainname = "domain\user"
.firstname = "Stan"
.lastname = "Molda"
//set anything else you want here
End With
Dim userGuid as guid = s.Create(newUser)
//Next we need to assign the user a role
AssignRole(userGuid)
//Finally we need to assign them to the correct Time Zone
SetUserTimeZone(userGuid)
End Sub
Public Sub AssignRole(g as Guid)
Dim s as mscrm.CrmService = GetMyService()
Dim req As New mscrm.AssignUserRolesRoleRequest()
req.UserId = g
req.RoleIds = New Guid() {GetTheGuidForMyPrimaryRole()}
s.Execute(req)
End Sub
Public Sub SetUserTimeZone(g as Guid)
Dim s as mscrm.CrmService = GetMyService()
Dim r As New mscrm4.RetrieveUserSettingsSystemUserRequest()
r.ColumnSet = New mscrm3.AllColumns()
r.EntityId = New Guid(g)
Dim resp As mscrm.RetrieveUserSettingsSystemUserResponse = CType(s.Execute(r), mscrm.RetrieveUserSettingsSystemUserResponse)
Dim settings As mscrm.usersettings = CType(resp.BusinessEntity, mscrm.usersettings)
settings.timezonecode = New mscrm.CrmNumber
settings.timezonecode.Value = OUR_TIME_ZONE_CONSTANT
Dim update As New mscrm.UpdateUserSettingsSystemUserRequest()
update.Settings = settings
update.UserId = g
s.Execute(update)
End Sub
For C#, take a look at my question, Dynamics CRM: Create users with specific GUIDs, which does exactly what you want (but not exactly what I want :-P).

Resources