我们在设计原理图或者查看原理图时,经常需要到网站上搜索某个元器件的相关资料,看能否找到规格书来查看。每次都要打开相关网站,输入关键词去搜索,这样的重复操作效率不是很高。有没有办法在原理图上,选中某个元器件,下一步就已经在网站上搜索了这个元器件的关键词,并找出了相关网页来。答案是有的,就是编写一个脚本,选中某个元器件,运行脚本就能实现这个功能。下面介绍一下这个方法。
首先,打开原理图的脚本编辑器,编写以下代码。
参考代码:
Sub Main
Begin Dialog UserDialog 260,140,"Select a Web ",.CallbackFunc ' %GRID:10,7,1,1
Text 50,84,170,14,"",.Text1
OKButton 40,112,90,21,.OK
CancelButton 140,112,90,21
OptionGroup .Manufacturer
OptionButton 60,14,140,14,"baidu",.OptionButton1
OptionButton 60,35,90,14,"szlcsc",.OptionButton2
OptionButton 60,56,90,14,"taobao",.OptionButton3
End Dialog
Dim dlg As UserDialog
Dim attrs As Attributes
If Dialog(dlg) = -1 Then 'OK was pressed
Set objs = ActiveDocument.GetObjects(plogObjectTypeComponent, "", True)
For Each part In objs
Set attrs = part.Attributes
compName = attrs("Value")
Next part
'compName = objs.Item(1).AttrVal(part, "Description")
Set ie = CreateObject("InternetExplorer.Application")
'compName = objs.Item(1).AttrVal(part, "Description")
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
Select Case dlg.Manufacturer
Case 0
'ie.Navigate("http://www-s.ti.com/sc/docs/psheets/pids2.htm")
ie.Navigate("http://www.baidu.com/s?wd="& compName)
SendKeys compName & "~"
Case 1
ie.Navigate("https://so.szlcsc.com/global.html?&hot-key=CC2530F256RHAR")
Case 2
ie.Navigate("https://s.taobao.com/search?keywords=" & compName)
End Select
End If
End Sub
Rem See DialogFunc help topic for more information.
Private Function CallbackFunc(DlgItem$, Action%, SuppValue%) As Boolean
Select Case Action%
Case 1 ' Dialog box initialization
Document_SelectionChange
Case 2 ' Value changing or button pressed
Case 3 ' TextBox or ComboBox text changed
Case 4 ' Focus changed
Case 5 ' Idle
Rem CallbackFunc = True ' Continue getting idle actions
End Select
End Function
Public Sub Document_SelectionChange()
Set objs = ActiveDocument.GetObjects(plogObjectTypeComponent, "", True)
DlgEnable "OK", False
If objs.Count = 1 Then
compName = objs.Item(1).Name
DlgText "Text1", "Selected Part: " & compName
DlgEnable "OK", True
ElseIf objs.Count > 1 Then
DlgText "Text1", "Multiple Selection"
Else
DlgText "Text1", "Select a part"
End If
End Sub
然后,选中需要查找的元器件,运行脚本,就会弹出一个网站的页面让我们选择,这里设置了百度,立创和淘宝。
最后,任选其中一个网站,点击确认,就会自动打开相对应的网站,搜索元器件的关键词,找到相关的内容供我们查看,非常方便快捷。
所需积分:10
下载资料需要登录,并消耗一定积分。
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉