Your Products have been synced, click here to refresh
Option Explicit Sub GetTheos() ' Post: http://www.pcdmisforum.com/forum/pc-dmis-enterprise-metrology-software/pc-dmis-code-samples/411735-vb-script-using-puttext-to-enter-an-expression Dim PCDApp As PCDLRN.Application Dim PCDPartPrograms As PCDLRN.PartPrograms Dim PCDPartProgram As PCDLRN.PartProgram Dim PCDCommands As PCDLRN.Commands Dim cmd As PCDLRN.Command Dim editWin As PCDLRN.EditWindow Set PCDApp = CreateObject("PCDLRN.Application") Set PCDPartPrograms = PCDApp.PartPrograms Set PCDPartProgram = PCDApp.ActivePartProgram Set PCDCommands = PCDPartProgram.Commands Set editWin = PCDPartProgram.EditWindow Dim fcntr As Integer Dim FeatureList$(99999) Dim TX, TY, TZ, NewTX, NewTY, NewTZ, txtBlock, txtBlockTmp, MSG As String Dim lastChr, findTHEO, findChr, firstComma, secondComma As Integer fcntr = 0 For Each cmd In PCDCommands If cmd.IsDCCFeature Or cmd.IsMeasuredFeature Then If cmd.Marked Then FeatureList(fcntr) = cmd.ID ' Eliminate spaces and linefeeds txtBlock = editWin.GetCommandText(cmd) txtBlock = Replace(txtBlock, " ", "") txtBlock = Replace(txtBlock, vbCr, "") txtBlock = Replace(txtBlock, vbCrLf, "") lastChr = Len(txtBlock) findTHEO = InStr(txtBlock, "THEO") - 1 ' Eliminate text before THEO and after. Results THEO/<X,Y,Z> txtBlock = Right(txtBlock, lastChr - findTHEO) findChr = InStr(txtBlock, ">,<") txtBlock = Left(txtBlock, findChr) ' Strip the block of text down to X,Y,Z txtBlock = Replace(txtBlock, "THEO/", "") txtBlock = Replace(txtBlock, "<", "") txtBlock = Replace(txtBlock, ">", "") firstComma = InStr(txtBlock, ",") secondComma = InStrRev(txtBlock, ",") MSG = "feature ID = " & FeatureList(fcntr) TX = Mid(txtBlock, 1, firstComma - 1) TY = Mid(txtBlock, firstComma + 1, (secondComma - firstComma) - 1) TZ = Mid(txtBlock, secondComma + 1, lastChr) NewTX = TX & "+0" NewTY = TY & "+0" NewTZ = TZ & "+0" MSG = MSG & Chr(10) & Chr(10) & "XTheo = " & TX MSG = MSG & Chr(10) & Chr(10) & "YTheo = " & TY MSG = MSG & Chr(10) & Chr(10) & "ZTheo = " & TZ MSG = MSG & Chr(10) & Chr(10) & "NewXTheo = " & NewTX MSG = MSG & Chr(10) & Chr(10) & "NewYTheo = " & NewTY MSG = MSG & Chr(10) & Chr(10) & "NewZTheo = " & NewTZ MsgBox MSG End If End If Next cmd Set PCDApp = Nothing Set PCDPartPrograms = Nothing Set PCDPartProgram = Nothing End Sub
Option Explicit Sub GetTheos() ' Post: http://www.pcdmisforum.com/forum/pc-dmis-enterprise-metrology-software/pc-dmis-code-samples/411735-vb-script-using-puttext-to-enter-an-expression Dim PCDApp As PCDLRN.Application Dim PCDPartPrograms As PCDLRN.PartPrograms Dim PCDPartProgram As PCDLRN.PartProgram Dim PCDCommands As PCDLRN.Commands Dim cmd As PCDLRN.Command Dim editWin As PCDLRN.EditWindow Set PCDApp = CreateObject("PCDLRN.Application") Set PCDPartPrograms = PCDApp.PartPrograms Set PCDPartProgram = PCDApp.ActivePartProgram Set PCDCommands = PCDPartProgram.Commands Set editWin = PCDPartProgram.EditWindow Dim fcntr As Integer Dim FeatureList$(99999) Dim TX, TY, TZ, NewTX, NewTY, NewTZ, txtBlock, txtBlockTmp, MSG As String Dim lastChr, findTHEO, findChr, firstComma, secondComma As Integer fcntr = 0 For Each cmd In PCDCommands If cmd.IsDCCFeature Or cmd.IsMeasuredFeature Then If cmd.Marked Then FeatureList(fcntr) = cmd.ID ' Eliminate spaces and linefeeds txtBlock = editWin.GetCommandText(cmd) txtBlock = Replace(txtBlock, " ", "") txtBlock = Replace(txtBlock, vbCr, "") txtBlock = Replace(txtBlock, vbCrLf, "") lastChr = Len(txtBlock) findTHEO = InStr(txtBlock, "THEO") - 1 ' Eliminate text before THEO and after. Results THEO/<X,Y,Z> txtBlock = Right(txtBlock, lastChr - findTHEO) findChr = InStr(txtBlock, ">,<") txtBlock = Left(txtBlock, findChr) ' Strip the block of text down to X,Y,Z txtBlock = Replace(txtBlock, "THEO/", "") txtBlock = Replace(txtBlock, "<", "") txtBlock = Replace(txtBlock, ">", "") firstComma = InStr(txtBlock, ",") secondComma = InStrRev(txtBlock, ",") MSG = "feature ID = " & FeatureList(fcntr) TX = Mid(txtBlock, 1, firstComma - 1) TY = Mid(txtBlock, firstComma + 1, (secondComma - firstComma) - 1) TZ = Mid(txtBlock, secondComma + 1, lastChr) NewTX = TX & "+0" NewTY = TY & "+0" NewTZ = TZ & "+0" MSG = MSG & Chr(10) & Chr(10) & "XTheo = " & TX MSG = MSG & Chr(10) & Chr(10) & "YTheo = " & TY MSG = MSG & Chr(10) & Chr(10) & "ZTheo = " & TZ MSG = MSG & Chr(10) & Chr(10) & "NewXTheo = " & NewTX MSG = MSG & Chr(10) & Chr(10) & "NewYTheo = " & NewTY MSG = MSG & Chr(10) & Chr(10) & "NewZTheo = " & NewTZ MsgBox MSG End If End If Next cmd Set PCDApp = Nothing Set PCDPartPrograms = Nothing Set PCDPartProgram = Nothing End Sub
© 2024 Hexagon AB and/or its subsidiaries. | Privacy Policy | Cloud Services Agreement |