block instances and properties

Hello All,

I am doing schematics just as drawings in SW and I created a bunch of blocks that I use all the time, most of them I imported from AutoCAD. I drop the pinout from a machine in and all the attributes are labeled as follows.

I:1/09 where I = Input Card 1 = slot and 9 = bit.

When I drop one of these cards in I have been going through and manually changing all of the attributes. This is usually just changing the slot numbers on all the attributes. What I would like to do is pull in a block set one attribute and all of the slot numbers will change. Is this possible?

I was thinking linked properties would offer a way to do this. I can not seem to set a property that is only useful to one instance of the block.

Thank you,

Reply to
blisspikle
Loading thread data ...

You can use custom properties but only if you only need a single block in the drawing. Another thing you can do is to use a macro that would fill the attributes on insertion or from a custom property or a string from the user

Reply to
CS

Is there a good place to learn about macro programming in solidworks? I do quite a bit of excel and this seems a little different. I tried recording a macro that I could select the block that I want to change and play a macro. I can not seem to get it working.

Thank you,

Reply to
blisspikle

Not all the functionality of the GUI is available in the API. A shame it is; but that is how it is. It may be with blocks that you have to figure it out as I think they are treated as annotations. Now as to learning the SW API there is a lot of information available. Go into the downloads section of the SW website and look through the two API download sections. There are specific examples and what amount to tutorials on how SW wants you to do things. I wouldn't call either rigourously complete, but there is a lot there.

Reply to
TOP

Here is what I would do. Since you are going to have alot of coppies of a block in one drawing I would create the block with one attribute that is invisible named something like BlockName-ID since it is invisible you can use this ID to Identify which block is which for later editing if needed.

I would have your program insert the block and fill it in from a form or something.

Set MyBlock = dwgdoc.insertBlock(PathOnly + "\BlockName.SLDBLK", x, y,

0#, Bscale) 'note the x and y dims are in meters so you will have to convert your units to meters 'Then You can edit the text of the block MyBlock.SetAttributeValue "BlockName-ID", "BlockName-1"

'then you can retriev these values like this

msgbox = MyBlock.GetAttributeValue("BlockName-ID")

'You can also find your block later

Set thisView = dwgdoc.GetFirstView Set blockInst = thisView.GetFirstBlockInstance while blockInst.GetAttributeValue("BlockName-ID") "BlockName-1" and not BlockInst is nothing blockInst = BlockInst.GetNext wend

If blockInst is nothing then Msgbox "Didn't find an instance named BlockName-1" exit sub end if

'if your code gets here then you have your block instance found

Good luck

Corey

Reply to
CS

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.